读取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基本的几何对象的更多相关文章

  1. Envelope几何对象 Curve对象几何对象 Multipatch几何对象 Geometry集合接口 IGeometryCollection接口

    Envelope是所有几何对象的外接矩形,用于表示几何对象的最小边框,所有的几何对象都有一个Envelope对象,IEnvelope是Envelope对象的主要接口,通过它可以获取几何对象的XMax, ...

  2. arcgis for silverlight 地图放大到某个点或者几何对象

    http://blog.csdn.net/xuan444150/article/details/7727866   分类: silverlight王国 GIS王国 2012-07-09 08:50 1 ...

  3. arcgis几何对象

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  4. R语言与医学统计图形-【18】ggplot2几何对象汇总

    ggplot2绘图系统--几何对象汇总 前面介绍了常见的几种基本的几何对象,并且介绍了scale.stat等其他要素.后续将介绍position.themes.coord和faceting等函数. 这 ...

  5. R语言与医学统计图形-【17】ggplot2几何对象之热图

    ggplot2绘图系统--heatmap.geom_rect 这里不介绍更常见的pheatmap包. 1.heatmap函数 基础包. data=as.matrix(mtcars) #接受矩阵 hea ...

  6. R语言与医学统计图形-【15】ggplot2几何对象之线图

    ggplot2绘图系统--几何对象之线图 曲线:点连线.路径曲线.时间序列曲线.模型拟合曲线...... 直线:水平直线.垂直直线.斜线. 1.曲线 对象及其参数. #路径图 geom_path(ma ...

  7. R语言与医学统计图形-【13】ggplot2几何对象之盒形图

    ggplot2绘图系统--几何对象之盒形图 参数: geom_boxplot(mapping = , #lower,middle,upper,x,ymax,ymin必须(有默认) #alpha/col ...

  8. R语言与医学统计图形-【11】ggplot2几何对象之散点图

    ggplot2绘图系统--几何对象之散点图 以geom开头的函数超过30个.几何对象和标度函数scale密不可分.只有在aes中传入某个变量,scale才能发挥作用. 所谓标度scale,就是图形遥控 ...

  9. R语言与医学统计图形-【14】ggplot2几何对象之直方密度图

    ggplot2绘图系统--几何对象之直方图.密度图 1.直方图 参数. geom_histogram(mapping = , data = , stat = 'bin', #统计变换,概率密度为den ...

随机推荐

  1. Android Studio开发第二篇创建新项目

    创建新项目很简单,File-New-New Project,这个没什么好说的跟Eclipse都差不都. 第二步SDK选择,有手机平板还有Wear,TV,汽车Auto,谷歌眼镜等几个种平台,这里就先选择 ...

  2. mongodb new file allocation failure

    话说那天正在向mongodb中写入数据,突然就蹦出了 new file allocation failure ,以为是数据有错误,就检查了一番,可没问题啊,看着像是mongo自己的问题,于是百度了一番 ...

  3. Kubernetes – Ingress

    用户在 Kubernetes 上部署的服务一般运行于私有网络,Pod和Service 提供了 hostPort,NodePort等参数用于暴露这些服务端口到K8S节点上,供使用者访问.这样的方法有明显 ...

  4. C - Monthly Expense

    Farmer John is an astounding accounting wizard and has realized he might run out of money to run the ...

  5. vue 实现聊天框滚动到底

    在需要出现滚动条的 DOM上添加 v-scroll 属性: <div class="chat-box" v-scroll="{auto: true}"&g ...

  6. 夺冠概率|2012年蓝桥杯B组题解析第九题-fishers

    (17')夺冠概率 足球比赛具有一定程度的偶然性,弱队也有战胜强队的可能. 假设有甲.乙.丙.丁四个球队.根据他们过去比赛的成绩,得出每个队与另一个队对阵时取胜的概率表: 甲 乙 丙 丁 甲 - 0. ...

  7. elasticsearch.yml配置文件

        Elasticsearch的配置文件在config文件夹下,其中有elasticsearch.yml.logging.yml两个配置文件,其中elasticsearch.yml是用来配置Ela ...

  8. df

    hdu 1052 Tian Ji -- The Horse Racing (2011-08-26 08:32:51) 转载▼ 标签: 杂谈 分类: acm杂谈 Tian Ji -- The Horse ...

  9. db2 reorg table failed处理

    概要: 当对一个表的结构进行改变后,需要reorg表,重新组织其目录统计信息,为数据库的访问计划提供信息,以便高效执行对其的操作. 对表作reorg操作,发生错误,通过db2 "? sql0 ...

  10. CH 1401 - 兔子与兔子 - [字符串hash]

    题目链接:传送门 描述 很久很久以前,森林里住着一群兔子.有一天,兔子们想要研究自己的 DNA 序列.我们首先选取一个好长好长的 DNA 序列(小兔子是外星生物,DNA 序列可能包含 26 个小写英文 ...