geotools中的空间关系(Geometry Relation
概述:
本文讲述geotools中的空间关系判断(Geometry Relationships)和空间操作(Geometry Operations)的编码实现。
空间关系(Geometry Relationships):
常见的空间关系(Geometry Relationships)包括:Disjoint、Intersects、Touches、Crosses、Within、Contains、Overlaps、Relates。
空间操作(Geometry Operations):
常见的空间操作(Geometry Operations)包括:Buffer、Intersection、ConvexHull、Intersection、Union、Difference、SymDifference。
代码实现:
1、测试数据
[java]view plaincopy
String wktPoint ="POINT(103.83489981581 33.462715497945)";
String wktLine ="LINESTRING(108.32803893589 41.306670233001,99.950999898452 25.84722546391)";
String wktPolygon ="POLYGON((100.02715479879 32.168082192159,102.76873121104 37.194305614622,107.0334056301 34.909658604412,105.96723702534 30.949603786713,100.02715479879 32.168082192159))";
String wktPolygon1 ="POLYGON((96.219409781775 32.777321394882,96.219409781775 40.240501628236,104.82491352023001 40.240501628236,104.82491352023001 32.777321394882,96.219409781775 32.777321394882))";
测试数据地图展示如下:
2、空间关系
[java]view plaincopy
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
WKTReader reader =newWKTReader( geometryFactory );
Point point = (Point) reader.read(wktPoint);
LineString line = (LineString) reader.read(wktLine);
Polygon polygon = (Polygon) reader.read(wktPolygon);
Polygon polygon1 = (Polygon) reader.read(wktPolygon1);
System.out.println("-------空间关系判断-------");
System.out.println(polygon.contains(point));
System.out.println(polygon.intersects(line));
System.out.println(polygon.overlaps(polygon1));
控制台输出结果如下:
3、空间操作
[java]view plaincopy
System.out.println("\r\n-------空间计算-------");
WKTWriter write =newWKTWriter();
Geometry intersection = polygon.union( polygon1 );
Geometry union = polygon.union( polygon1 );
Geometry difference = polygon.difference( polygon1 );
Geometry symdifference = polygon.symDifference( polygon1 );
System.out.println("\t+++++++++++叠加分析+++++++++++");
System.out.println(write.write(intersection));
System.out.println("\t+++++++++++合并分析+++++++++++");
System.out.println(write.write(union));
System.out.println("\t+++++++++++差异分析+++++++++++");
System.out.println(write.write(difference));
System.out.println("\t+++++++++++sym差异分析+++++++++++");
System.out.println(write.write(symdifference));
控制台输出结果如下:
空间操作的计算结果展示如下:
intersect
union
Difference
SymDifference
---------------------------------------------------------------------------------------------------------------
技术博客
http://blog.csdn.NET/gisshixisheng
在线教程
http://edu.csdn.Net/course/detail/799
Github
https://github.com/lzugis/
联系方式
q q:1004740957
e-mail:niujp08@qq.com
公众号:lzugis15
Q Q 群:452117357(webgis)
337469080(Android)