GEOS库学习之四:几何关系判断
2015-11-16 10:35
253 查看
原理上一篇已经介绍过了,这篇就直接进行程序练习
结果如下:
#include "geos.h" GeometryFactory factory; //创建一条环线,与线的区别就是环线是闭合的。即第一个点和最后一点重合 LinearRing* createGeosRing(double x,double y,double offset) { CoordinateArraySequenceFactory csf; CoordinateSequence* cs = csf.create(6,2); cs->setAt(Coordinate(x,y),0); cs->setAt(Coordinate(x,y+offset),1); cs->setAt(Coordinate(x+offset,y+offset),2); cs->setAt(Coordinate(x+2*offset,y+2*offset),3); cs->setAt(Coordinate(x+2*offset,y),4); cs->setAt(Coordinate(x,y),5); //与第一个点相等 LinearRing *lr=factory.createLinearRing(cs); return lr; } //创建一个多边形,如果多边形内部没有孔洞实际上与环线是一样的 Polygon* createGeosPolygon(double x,double y,double offset) { LinearRing *lr=createGeosRing(x,y,offset); Polygon *poly=factory.createPolygon(lr,NULL); //如果多边形中间没有孔洞,第二个参数设为NULL return poly; } int main() { Polygon *p1=createGeosPolygon(12,12,5); //创建第一个多边形 for(int i=0;i<=20;i++) { cout<<i<<": "; Polygon *p2=createGeosPolygon(0,0,i); //创建第二个多边形 IntersectionMatrix *im=p2->relate(p1); cout<<*im<<" "; //返回DE-9IM交叉矩阵 if(p2->disjoint(p1)) cout<<"不相交"<<endl; else { if(p2->touches(p1)) cout<<"接触"<<endl; else if(p2->overlaps(p1)) cout<<"部分重叠"<<endl; else if(p2->covers(p1)) cout<<"覆盖"<<endl; else cout<<*im<<endl; } } system("pause"); return 1; }
结果如下:
相关文章推荐
- Servlet程序开发-Helloworld
- ios机器上span标签绑定点击事件无效
- PHP程序猿必备的七种武器
- Redis 详解 (一) StackExchange.Redis Client
- 跟我学习javascript的全局变量
- 蓝牙低能耗技术简介
- zabbix监控mysql客户端
- 广告点击率预测
- C输入输出
- 【C语言】 冒泡排序
- socket编程基础2(socket API函数介绍)
- Linux系统下安装Intellij IDEA
- OC中的面向对象语法3
- 变量和数据类型
- screen 常用命令
- CCS5.5.0修改编辑栏的背景颜色
- 转发和重定向的区别
- Linux登录提示性信息
- Android Studio百度地图入门(导入jar与so文件)
- 【学习日记】javaIO流的知识点总结(2)