这里写目录标题
- 版本
- JTS disjoint intersects
- 俩个图形不相交
- 俩个图形 边相交
- 俩个图形 内部相交
- 俩个图形 点相交
版本
org.locationtech.jts:jts-core:1.19.0
链接: github
JTS disjoint intersects
不相交的 九交模型FF*FF****
相交的 九交模型
[T********] [*T*******] [***T*****] [****T****]
俩个图形不相交
/*** 俩个图形 完全不相交*/public void test00() {Coordinate[] coordinates1 = new Coordinate[] {new Coordinate(1, 1), new Coordinate(1, 4), new Coordinate(5, 4), new Coordinate(5, 1), new Coordinate(1, 1)};Polygon polygon1 = geometryFactory.createPolygon(coordinates1);Coordinate[] coordinates2 = new Coordinate[] {new Coordinate(6, 1), new Coordinate(6, 4), new Coordinate(10, 4), new Coordinate(10, 1), new Coordinate(6, 1)};Polygon polygon2 = geometryFactory.createPolygon(coordinates2);LOGGER.info("polygon1 - polygon2 九交模型值:{}", polygon1.relate(polygon2).toString());LOGGER.info("polygon1 - polygon2 不相交:{}", polygon1.disjoint(polygon2));LOGGER.info("polygon1 - polygon2 相交:{}", polygon1.intersects(polygon2));}
17:35:11.796 [main] INFO pers.stu.geometry.GeometryEquals - polygon1 - polygon2 九交模型值:FF2FF1212
17:35:11.798 [main] INFO pers.stu.geometry.GeometryEquals - polygon1 - polygon2 不相交:true
17:35:11.798 [main] INFO pers.stu.geometry.GeometryEquals - polygon1 - polygon2 相交:false
俩个图形 边相交
public void test01() {Coordinate[] coordinates1 = new Coordinate[] {new Coordinate(1, 1), new Coordinate(1, 4), new Coordinate(5, 4), new Coordinate(5, 1), new Coordinate(1, 1)};Polygon polygon1 = geometryFactory.createPolygon(coordinates1);Coordinate[] coordinates2 = new Coordinate[] {new Coordinate(5, 1), new Coordinate(5, 4), new Coordinate(9, 4), new Coordinate(9, 1), new Coordinate(5, 1)};Polygon polygon2 = geometryFactory.createPolygon(coordinates2);LOGGER.info("polygon1 - polygon2 九交模型值:{}", polygon1.relate(polygon2).toString());LOGGER.info("polygon1 - polygon2 不相交:{}", polygon1.disjoint(polygon2));LOGGER.info("polygon1 - polygon2 相交:{}", polygon1.intersects(polygon2));}
17:38:21.241 [main] INFO pers.stu.geometry.GeometryEquals - polygon1 - polygon2 九交模型值:FF2F11212
17:38:21.243 [main] INFO pers.stu.geometry.GeometryEquals - polygon1 - polygon2 不相交:false
17:38:21.243 [main] INFO pers.stu.geometry.GeometryEquals - polygon1 - polygon2 相交:true
俩个图形 内部相交
public void test02() {Coordinate[] coordinates1 = new Coordinate[] {new Coordinate(1, 1), new Coordinate(1, 4), new Coordinate(5, 4), new Coordinate(5, 1), new Coordinate(1, 1)};Polygon polygon1 = geometryFactory.createPolygon(coordinates1);Coordinate[] coordinates2 = new Coordinate[] {new Coordinate(3, 1), new Coordinate(3, 4), new Coordinate(7, 4), new Coordinate(7, 1), new Coordinate(3, 1)};Polygon polygon2 = geometryFactory.createPolygon(coordinates2);LOGGER.info("polygon1 - polygon2 九交模型值:{}", polygon1.relate(polygon2).toString());LOGGER.info("polygon1 - polygon2 不相交:{}", polygon1.disjoint(polygon2));LOGGER.info("polygon1 - polygon2 不相交:{}", polygon1.disjoint(polygon2));LOGGER.info("polygon1 - polygon2 相交:{}", polygon1.intersects(polygon2));}
19:01:28.663 [main] INFO pers.stu.geometry.GeometryEquals - polygon1 - polygon2 九交模型值:212111212
19:01:28.665 [main] INFO pers.stu.geometry.GeometryEquals - polygon1 - polygon2 不相交:false
19:01:28.665 [main] INFO pers.stu.geometry.GeometryEquals - polygon1 - polygon2 不相交:false
19:01:28.665 [main] INFO pers.stu.geometry.GeometryEquals - polygon1 - polygon2 相交:true
俩个图形 点相交
public void test03() {Coordinate[] coordinates1 = new Coordinate[] {new Coordinate(1, 1), new Coordinate(1, 4), new Coordinate(5, 4), new Coordinate(5, 1), new Coordinate(1, 1)};Polygon polygon1 = geometryFactory.createPolygon(coordinates1);Coordinate[] coordinates2 = new Coordinate[] {new Coordinate(5, 4), new Coordinate(5, 7), new Coordinate(9, 7), new Coordinate(9, 4), new Coordinate(5, 4)};Polygon polygon2 = geometryFactory.createPolygon(coordinates2);LOGGER.info("polygon1 - polygon2 九交模型值:{}", polygon1.relate(polygon2).toString());LOGGER.info("polygon1 - polygon2 不相交:{}", polygon1.disjoint(polygon2));LOGGER.info("polygon1 - polygon2 相交:{}", polygon1.intersects(polygon2));}
19:04:51.530 [main] INFO pers.stu.geometry.GeometryEquals - polygon1 - polygon2 九交模型值:FF2F01212
19:04:51.533 [main] INFO pers.stu.geometry.GeometryEquals - polygon1 - polygon2 不相交:false
19:04:51.533 [main] INFO pers.stu.geometry.GeometryEquals - polygon1 - polygon2 相交:true