[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 ...
随机推荐
- Arduino基本数据类型
基本数据类型简介 常见的Arduino是基于ATmega的8位 AVR单片机,例如Arduino UNO ,Arduino Nano,Arduino mega2560等.还有高级点 32位的,如Ard ...
- day_5.28 py网络编程
端口 socket简介: socket为一个类 s接收的是返回的对象引用 2018-5-28 15:52:47 开始进行网络编程 udp 套接字 encode() 编码 decode() 解码 ' ...
- nodejs--get请求数据解析
---- 三种方式解析: 1.自动动手切 2.api的querystring模块 3.api的url模块
- 树剖+线段树||树链剖分||BZOJ1984||Luogu4315||月下“毛景树”
题面:月下“毛景树” 题解:是道很裸的树剖,但处理的细节有点多(其实是自己线段树没学好).用一个Dfs把边权下移到点权,用E数组记录哪些边被用到了:前三个更新的操作都可以合并起来,可以发现a到b节点间 ...
- 品尝阿里云容器服务:初步尝试ASP.NET Core Web API站点的Docker自动化部署
部署场景是这样的,我们基于 ASP.NET Core 2.0 Preview 1 开发了一个用于管理缓存的 Web API ,想通过阿里云容器服务基于 Docker 部署为内网服务. 在这篇博文中分享 ...
- Ubuntu 16.04 编译OpenCV 问题解决stdlib.h: No such file or directory
https://blog.csdn.net/xinyu391/article/details/72867510 https://ask.csdn.net/questions/365969
- CH 2101 - 可达性统计 - [BFS拓扑排序+bitset状压]
题目链接:传送门 描述 给定一张N个点M条边的有向无环图,分别统计从每个点出发能够到达的点的数量.N,M≤30000. 输入格式 第一行两个整数N,M,接下来M行每行两个整数x,y,表示从x到y的一条 ...
- BZOJ 3224 - 普通平衡树 - [Treap][Splay]
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3224 Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中 ...
- 1.7Oob同类中不同方法间的互相调用
import java.util.Scanner; public class Bill { public static final double RATE=150.0; 这里没有创建getter和se ...
- piano class 13
1,手放在琴键上,不妨碍另外一只手弹奏即可 2,识别五线谱可以加上几条线,减去几条线,一下子就记住了所有的 3,弹得还是有点快,要慢弹奏,四四拍的理论上比四三拍的还要慢,也要看风格 4,四二拍,强弱, ...