zoukankan      html  css  js  c++  java
  • postgresql数据库shape字段转C++ shape对象

    1.数据库查询shape的文本字符串

    SELECT REPLACE(REPLACE(CAST(st_astext(shape) AS TEXT),'LINESTRING ( ',''),')','') shape from road ORDER BY road_ ;

    2.文本字符串转 vector<point>
    CreatePointVec(c[0].as<string>().c_str(), my_road.m_vPoints);

    void RoadData::CreatePointVec(CString XY_str, vector<CAutoPoint> &vecPoint)
    {
     vector<CString> v_point = SplitCString(XY_str, ",");

     int n_of_point = v_point.size();

     for (size_t i = 0; i < n_of_point; i++)
     {
      vector<CString> temp_xy = SplitCString(v_point[i], " ");

      double x = atof(temp_xy[0]) * 3600;
      double y = atof(temp_xy[1]) * 3600;
      CAutoPoint pt(x, y);

      vecPoint.push_back(pt);
      //printf("%f,%f;", x, y);
     }
    }


    vector<CString> RoadData::SplitCString(CString strSource, CString ch)
    {
     vector<CString> vecString;
     int iPos = 0;
     CString strTmp;
     strTmp = strSource.Tokenize(ch, iPos);
     while (strTmp.Trim() != _T(""))
     {
      vecString.push_back(strTmp);
      strTmp = strSource.Tokenize(ch, iPos);
     }
     return vecString;
    }


    3.点集合转shape

    SHPObject*  m_pShapeObject = points2obj(RoadLinkDBF.m_vPoints, SHPT_ARC);

    SHPObject * CAutoMap::points2obj(vector<CAutoPoint> v_point, int TYPE)
    {

     int n_of_point = v_point.size();

     double* padfX = new double[n_of_point];
     double* padfY = new double[n_of_point];

     for (int i = 0;i < v_point.size(); i++)
     {
      padfX[i] = v_point[i].x;
      padfY[i] = v_point[i].y;
     }

     SHPObject * result_shape = SHPCreateSimpleObject(TYPE, n_of_point, padfX, padfY, NULL);

     delete []padfX;
     delete []padfY;

     return result_shape;
    }

  • 相关阅读:
    Editor REST Client
    log配置
    spring-boot-configuration-processor
    http请求
    做项目用到的一些正则表达式,贴出来共享
    批量插入的实现
    sql执行顺序对比
    Java常用的并发工具类:CountDownLatch、CyclicBarrier、Semaphore、Exchanger
    spring中bean的生命周期
    多属性的对象列表的两种排序方法
  • 原文地址:https://www.cnblogs.com/roea1/p/13284045.html
Copyright © 2011-2022 走看看