[geos]Geometry基本的几何对象
读取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<int, int> 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<pcl_t_cloud->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<num_of_hists)
{
cell_residual[indx].first = indx;
int ptscount=cell_residual[indx].second;
cell_residual[indx].second = ptscount+1;
}
}
}
//排序高度数组
std::sort (cell_residual.begin (), cell_residual.end (), comparePair2);
//得到最大和最小值,统计数目最多的两个
double minZ=cell_residual[num_of_hists-2].first*interval + minPt.z;
double maxZ=cell_residual[num_of_hists-1].first*interval + minPt.z;
//赋值2个属性
DBFWriteDoubleAttribute(hDBF, iShape ,idxCeiling,std::min(minZ,maxZ) );
DBFWriteDoubleAttribute(hDBF, iShape ,idxFloor,std::max(minZ,maxZ) );
cell_residual.clear();
}
}
DBFClose( hDBF );
SHPClose(hShp);
[geos]Geometry基本的几何对象的更多相关文章
- Envelope几何对象 Curve对象几何对象 Multipatch几何对象 Geometry集合接口 IGeometryCollection接口
Envelope是所有几何对象的外接矩形,用于表示几何对象的最小边框,所有的几何对象都有一个Envelope对象,IEnvelope是Envelope对象的主要接口,通过它可以获取几何对象的XMax, ...
- arcgis for silverlight 地图放大到某个点或者几何对象
http://blog.csdn.net/xuan444150/article/details/7727866 分类: silverlight王国 GIS王国 2012-07-09 08:50 1 ...
- arcgis几何对象
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- R语言与医学统计图形-【18】ggplot2几何对象汇总
ggplot2绘图系统--几何对象汇总 前面介绍了常见的几种基本的几何对象,并且介绍了scale.stat等其他要素.后续将介绍position.themes.coord和faceting等函数. 这 ...
- R语言与医学统计图形-【17】ggplot2几何对象之热图
ggplot2绘图系统--heatmap.geom_rect 这里不介绍更常见的pheatmap包. 1.heatmap函数 基础包. data=as.matrix(mtcars) #接受矩阵 hea ...
- R语言与医学统计图形-【15】ggplot2几何对象之线图
ggplot2绘图系统--几何对象之线图 曲线:点连线.路径曲线.时间序列曲线.模型拟合曲线...... 直线:水平直线.垂直直线.斜线. 1.曲线 对象及其参数. #路径图 geom_path(ma ...
- R语言与医学统计图形-【13】ggplot2几何对象之盒形图
ggplot2绘图系统--几何对象之盒形图 参数: geom_boxplot(mapping = , #lower,middle,upper,x,ymax,ymin必须(有默认) #alpha/col ...
- R语言与医学统计图形-【11】ggplot2几何对象之散点图
ggplot2绘图系统--几何对象之散点图 以geom开头的函数超过30个.几何对象和标度函数scale密不可分.只有在aes中传入某个变量,scale才能发挥作用. 所谓标度scale,就是图形遥控 ...
- R语言与医学统计图形-【14】ggplot2几何对象之直方密度图
ggplot2绘图系统--几何对象之直方图.密度图 1.直方图 参数. geom_histogram(mapping = , data = , stat = 'bin', #统计变换,概率密度为den ...
随机推荐
- U3D 垂直同步
Unity3D中新建一个场景空的时候,帧速率(FPS总是很低),大概在60~70之间.一直不太明白是怎么回事,现在基本上明白了.我在这里解释一下原因,如有错误,欢迎指正.在Unity3D中当运行场景打 ...
- 【laravel5.6】The Process class relies on proc_open, which is not available on your PHP installation.
部署服务器的时候,使用composer来安装依赖.遇到了 解决办法: 在php.ini中,找到disable_functions选项,看看后面是否有proc_open函数被禁用了,如果有的话,去掉即可
- G - Line of Sight
来源poj2074 An architect is very proud of his new home and wants to be sure it can be seen by people p ...
- IIS Asp.Net 访问 Com组件 报拒绝访问
IIS Asp.Net 访问 Com组件 报拒绝访问 解决方法: IIS 程序池->高级设置->进程模式->标识->内置帐户=LocalSystem
- 我学到的新知识之——Lotus Notes闪退如何修复
很多企业内部都在使用IBM 出品的Lotus Notes 来收发邮件,以及内置的SameTime作为内部交流工具,作为用了多年微软套装产品的我来说,还是有些不适应. 最近遇到一个案例,只要用户登陆sa ...
- 泡泡一分钟:A Multi-Position Joint Particle Filtering Method for Vehicle Localization in Urban Area
A Multi-Position Joint Particle Filtering Method for Vehicle Localization in Urban Area 城市车辆定位的多位置联合 ...
- deepin修改javahome不生效,一直显示openjdk解决
删除/usr/bin/java即可 terwer@terwer-PC:~$ sudo rm /usr/bin/java [sudo] terwer 的密码: terwer@terwer-PC:~$ j ...
- JS之JSON.parse和JSON.stringify
这两个函数有兼容性问题, 会报错JSON"未定义 解决方案, 引入json2.js,可以解决浏览器的兼容性 https://link.jianshu.com/?t=https://githu ...
- [tcpreplay] tcpreplay高级用法--使用tcpreplay-edit进行循环动态发包
tcpreplay-edit提供了可对包进行修改的高级用法: --unique-ip Modify IP addresses each loop iteration to generate uniqu ...
- spark学习笔记3
Spark 支持在集群范围内将数据集缓存至每一个节点的内存中,可避免数据传输,当数据需要重复访问时这个特征非常有用,例如查询体积小的“热”数据集,或是运行如 PageRank 的迭代算法.调用 cac ...