[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 ...
随机推荐
- 【netcore基础】.Net core使用swagger自动生成开发文档
之前写过一篇 .Net 版本的博客 https://www.cnblogs.com/jhli/p/8317566.html 现在只不过用了 netcore 之后的版本,其实差不多 netcore版本的 ...
- 60款很酷的 jQuery 幻灯片演示和下载【转】
jQuery 是一个非常优秀的 JavaScript 框架,使用简单灵活,同时还有许多成熟的插件可供选择,它可以帮助你在项目中加入漂亮的效果,其中之一就是幻灯片效果的实现,这是一种在有限的网页空间内展 ...
- java 中的闭包
原文地址:https://sylvanassun.github.io/2017/07/30/2017-07-30-JavaClosure/ 1.自由变量: function Add(y) { retu ...
- Quartz任务调度实践
最近在写一个任务调度程序,需要每隔几秒查询数据库,并取出数据做一些处理操作.使用到了Quartz任务调度框架. 基本概念 Quartz包含几个重要的对象,分别为任务(Job),触发器(Trigger) ...
- 基于jdk1.8的HashMap源码学习笔记
作为一种最为常用的容器,同时也是效率比较高的容器,HashMap当之无愧.所以自己这次jdk源码学习,就从HashMap开始吧,当然水平有限,有不正确的地方,欢迎指正,促进共同学习进步,就是喜欢程序员 ...
- AIX装机问题123
好久没有实施,好记性不如好笔记,那就记录下吧 1文件系统创建挂载 通过smit工具很容易简单举例创建一个jfs2类型文件系统并挂载 创建lv smit mklv 创建jfs2类型文件系统 指定lv s ...
- CentOS7(linux) 通过服务名查询安装目录
#ps aux|grep nginx root 1231 0.0 0.0 46336 956 ? Ss 04:21 0:00 nginx: master process /usr/sbin/nginx ...
- .NET Core开发日志——从搭建开发环境开始
.NET Core自2016年推出1.0版本开始,到目前已是2.1版本,在其roadmap计划里明年更会推出3.0版本,发展不可不谓之迅捷.不少公司在经过一个谨慎的观望期后,也逐步开始将系统升级至最新 ...
- [No0000166]CPU的组成结构及其原理
中央处理器(Central Processing Unit, CPU) CPU的基本架构和工作原理其实百科上讲得已经相当清楚了,不过我觉得有些事情呢还是给个例子出来比较方便学习.本文会先从内存地址,计 ...
- SQL之层次查询
层次查询是一种确定数据行间关系的一种操作手段.层次查询遍历的是一个树形结构.基本语法如下,以下语法嵌入到标准SQL中即可达到层次查询的目的: level,... ...[注释:伪列,用于select子 ...