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;
    }

  • 相关阅读:
    沉痛的一天
    PowerBuilder之5年经验谈(一之1)--PB对Unicode的支持
    C# Client API for Sphinx (support to 0.99)
    F#学习笔记基本类型
    F#学习笔记方法
    接口串联
    eclipse 中如何设置注释?
    软件测试过程中手机截屏
    Postan中执行接口时使用JSON数据,那么什么是 JSON?
    MySQL使用dump备份以及恢复备份
  • 原文地址:https://www.cnblogs.com/roea1/p/13284045.html
Copyright © 2011-2022 走看看