博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[geos]Geometry基本的几何对象
阅读量:6533 次
发布时间:2019-06-24

本文共 2453 字,大约阅读时间需要 8 分钟。

读取shp中的点,读取shp中的线,

(1)读取shp中的多边形,修改属性字段的值。

类库版本:geos3.6.2,shapelib1.3

定义类变量:

 GeometryFactory::unique_ptr global_factory;

构造中初始化

// Define a precision model using 0,0 as the reference origin// and 2.0 as coordinates scale.PrecisionModel *pm = new PrecisionModel(1.0, 0, 0);// Initialize global factory with defined PrecisionModel// and a SRID of -1 (undefined).global_factory = GeometryFactory::create(pm, -1);

 

方法体中调用:  

std::string::size_type pos=pszShapeFile.find('.'); 	/*std::string ext=filename.substr(pos==string::npos? pszShapeFile.length():pos+1); */	std::string tmp=pszShapeFile;	std::string dbfname=tmp.replace(tmp.begin()+pos+1,tmp.end(),"dbf");	SHPHandle hShp= SHPOpen(pszShapeFile.c_str(), "r");	DBFHandle	hDBF = DBFOpen( dbfname.c_str(), "r+b" );	if( hDBF == NULL )	{		return;	}	int idxCeiling=DBFGetFieldIndex(hDBF,"CeilingZ");	int idxFloor=DBFGetFieldIndex(hDBF,"FloorZ");	if (idxCeiling==-1)	{		idxCeiling=DBFAddField(hDBF,"CeilingZ",FTDouble, 10, 4);	}	if (idxFloor==-1)	{		idxFloor=DBFAddField(hDBF,"FloorZ",FTDouble, 10, 4);	}	int nShapeType, nVertices;	int nEntities = 0;	double* minB = new double[4];	double* maxB = new double[4];	SHPGetInfo(hShp, &nEntities, &nShapeType, minB, maxB);	printf("ShapeType:%d\n", nShapeType);	printf("Number of Rooms: %d\n", nEntities);	if (nShapeType==SHPT_POLYGON ||nShapeType==SHPT_POLYGONZ)	{		geos::geom::CoordinateArraySequenceFactory csf;		for (int idx = 0; idx < nEntities;idx++)		{			std::pair
pair; cell_residual.resize (num_of_hists, pair); int iShape = idx; SHPObject *obj = SHPReadObject(hShp, iShape); int parts = obj->nParts; int verts=obj->nVertices; printf("nParts:%d\n", parts); printf("nVertices:%d\n", verts); geos::geom::CoordinateSequence* cs1 = csf.create(verts,2); for (size_t j = 0; j < verts; j++) { double x = obj->padfX[j]; double y = obj->padfY[j]; cs1->setAt(Coordinate (x,y,0),j); } geos::geom::LinearRing* ring1 = global_factory->createLinearRing(cs1); geos::geom::Geometry* p1 = global_factory->createPolygon(ring1,NULL); //根据房间范围遍历每一个点 for (int i=0;i
points.size();i++) { pcl::PointXYZ pt=pcl_t_cloud->points[i]; geos::geom::Coordinate coord(pt.x,pt.y,0); geos::geom::Geometry* pt_g=global_factory->createPoint(coord); bool flag=p1->contains(pt_g); if (flag) { int indx=floor((pt.z-minPt.z)/interval); if (indx

  

转载于:https://www.cnblogs.com/yhlx125/p/7753445.html

你可能感兴趣的文章
MySql中is NULL、ISNULL()和IFNULL()运行速度的比较
查看>>
oracle-xe手工创建数据库
查看>>
Cisco交换机 链路聚合
查看>>
我的友情链接
查看>>
UG中卸载被占用的DLL
查看>>
eclipse 设置注释模板详解,与导入模板方法介绍总结
查看>>
Cocos2d-x3.2 文字显示
查看>>
估计下星期就能考科目二了
查看>>
轻松实现localStorage本地存储和本地数组存储
查看>>
mongodb group
查看>>
python+selenium自动化测试(二)
查看>>
(笔记 - 纯手敲)Spring的IOC和AOP 含GIT地址
查看>>
7-设计模式介绍
查看>>
让运维更高效:关于ECS系统事件
查看>>
J2EE分布式框架--单点登录集成方案
查看>>
跨域传递参数
查看>>
android 4.2的新特性layoutRtl,让布局自动从右往左显示
查看>>
iOS tableView 下拉列表的设计
查看>>
sharepoint 2010 属性编辑工具 SPCamlEditor 1.5.1
查看>>
linux下配置网络环境
查看>>