码迷,mamicode.com
首页 > 数据库 > 详细

postgresql数据库shape字段转C++ shape对象

时间:2020-07-11 17:03:29      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:sql   map   str   point   line   temp   split   token   ++   

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

 

postgresql数据库shape字段转C++ shape对象

标签:sql   map   str   point   line   temp   split   token   ++   

原文地址:https://www.cnblogs.com/roea1/p/13284045.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!