• JTS:11 Overlaps 部分重叠


    版本

    org.locationtech.jts:jts-core:1.19.0
    链接: github

    代码

    /**
     * 部分重叠
     */
    public class GeometryOverlaps {
    
        private final GeometryFactory geometryFactory = new GeometryFactory();
    
        private static final Logger LOGGER = LoggerFactory.getLogger(GeometryOverlaps.class);
    
        private static final WKTWriter WKT_WRITER = new WKTWriter();
    
        private Coordinate[] coordinate1;
    
        private Coordinate[] coordinate2;
    
        /**
         * 如果几何图形A和B在空间上重叠,则返回TRUE。
         * 如果两个几何图形具有相同的尺寸,每个几何图形至少有一个点不被另一个几何图形共享(或者等价地,两个几何图形都不覆盖另一个),并且它们内部的交点具有相同的尺寸,则两个几何图形重叠。
         * 这种重叠关系是对称的。
         */
        public static void main(String[] args) {
            GeometryOverlaps geometryOverlaps = new GeometryOverlaps();
            geometryOverlaps.test02();
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    1 多点与多点

    在这里插入图片描述

        /**
         * 多点与多点
         */
        public void test00() {
            coordinate1 = new Coordinate[] {
                    new Coordinate(1, 6), new Coordinate(7, 6),new Coordinate(7, 1), new Coordinate(1, 1),
                    new Coordinate(4, 3), new Coordinate(7, 6)
            };
    
            MultiPoint multiPoint1 = geometryFactory.createMultiPointFromCoords(coordinate1);
    
            coordinate2 = new Coordinate[] {
                    new Coordinate(2, 5), new Coordinate(6, 5),new Coordinate(6, 2), new Coordinate(2, 2),
                    new Coordinate(4, 3), new Coordinate(7, 6)
            };
    
            MultiPoint multiPoint2 = geometryFactory.createMultiPointFromCoords(coordinate2);
    
            LOGGER.info("multiPoint1 - multiPoint2 九交模型值:{}", multiPoint1.relate(multiPoint2).toString());
            LOGGER.info("multiPoint1 - multiPoint2 重叠:{}", multiPoint1.overlaps(multiPoint2));
            LOGGER.info("multiPoint1: {}, multiPoint2: {}", WKT_WRITER.write(multiPoint1), WKT_WRITER.write(multiPoint2));
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    16:18:38.992 [main] INFO  pers.stu.geometry.GeometryOverlaps - multiPoint1 - multiPoint2 九交模型值:0F0FFF0F2
    16:18:38.994 [main] INFO  pers.stu.geometry.GeometryOverlaps - multiPoint1 - multiPoint2 重叠:true
    16:18:39.000 [main] INFO  pers.stu.geometry.GeometryOverlaps - multiPoint1: MULTIPOINT ((1 6), (7 6), (7 1), (1 1), (4 3), (7 6)), multiPoint2: MULTIPOINT ((2 5), (6 5), (6 2), (2 2), (4 3), (7 6))
    
    • 1
    • 2
    • 3
    2 线与线

    在这里插入图片描述

        /**
         * 线与线
         */
        public void test01() {
            coordinate1 = new Coordinate[] {
                    new Coordinate(2, 7), new Coordinate(2, 4),new Coordinate(6, 4), new Coordinate(6, 7)
            };
    
            LineString lineString1 = geometryFactory.createLineString(coordinate1);
    
            coordinate2 = new Coordinate[] {
                    new Coordinate(2, 1), new Coordinate(2, 4),new Coordinate(6, 4), new Coordinate(6, 1)
            };
    
            LineString lineString2 = geometryFactory.createLineString(coordinate2);
    
            LOGGER.info("lineString1 - lineString2 九交模型值:{}", lineString1.relate(lineString2).toString());
            LOGGER.info("lineString1 - lineString2 重叠:{}", lineString1.overlaps(lineString2));
            LOGGER.info("lineString1: {}, lineString2: {}", WKT_WRITER.write(lineString1), WKT_WRITER.write(lineString2));
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    16:54:19.272 [main] INFO  pers.stu.geometry.GeometryOverlaps - lineString1 - lineString2 九交模型值:1F1FF0102
    16:54:19.274 [main] INFO  pers.stu.geometry.GeometryOverlaps - lineString1 - lineString2 重叠:true
    16:54:19.280 [main] INFO  pers.stu.geometry.GeometryOverlaps - lineString1: LINESTRING (2 7, 2 4, 6 4, 6 7), lineString2: LINESTRING (2 1, 2 4, 6 4, 6 1)
    
    • 1
    • 2
    • 3
    3 面与面

    在这里插入图片描述

        /**
         * 面与面
         */
        public void test02() {
            coordinate1 = new Coordinate[] {
                    new Coordinate(3, 8), new Coordinate(3, 3),new Coordinate(11, 3), new Coordinate(11, 8),
                    new Coordinate(3, 8)
            };
    
            Polygon polygon1 = geometryFactory.createPolygon(coordinate1);
    
            coordinate2 = new Coordinate[] {
                    new Coordinate(3, 5), new Coordinate(3, 1),new Coordinate(11, 1), new Coordinate(6, 1),
                    new Coordinate(3, 5)
            };
    
            Polygon polygon2 = geometryFactory.createPolygon(coordinate2);
    
            LOGGER.info("polygon1 - polygon2 九交模型值:{}", polygon1.relate(polygon2).toString());
            LOGGER.info("polygon1 - polygon2 重叠:{}", polygon1.overlaps(polygon2));
            LOGGER.info("polygon1: {}, polygon2: {}", WKT_WRITER.write(polygon1), WKT_WRITER.write(polygon2));
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    16:55:24.524 [main] INFO  pers.stu.geometry.GeometryOverlaps - polygon1 - lineString2 九交模型值:212111212
    16:55:24.526 [main] INFO  pers.stu.geometry.GeometryOverlaps - polygon1 - lineString2 重叠:true
    16:55:24.531 [main] INFO  pers.stu.geometry.GeometryOverlaps - polygon1: POLYGON ((3 8, 3 3, 11 3, 11 8, 3 8)), lineString2: POLYGON ((3 5, 3 1, 11 1, 6 1, 3 5))
    
    • 1
    • 2
    • 3
  • 相关阅读:
    UIView Animation 动画学习总结
    还在用Excel做报表?建议你试试这个数据填报系统_光点科技
    执法部门被网络攻击成趋势
    正则表达式模块re
    ZZNUOJ_用C语言编写程序实现1211:日期排序(附完整源码)
    使用XShell、XFTP 连接 win7 虚拟机(windows、Linux无法远程登录问题)
    开源一款基于EG1151的大功率同步整流可调升降压电源模块(支持TypeC PD快充输入)
    机器学习1综述
    SpringBoot @GroupSequenceProvider注解实现bean多属性联合校验
    基于深度Q学习的雅达利打砖块游戏博弈
  • 原文地址:https://blog.csdn.net/God_Father_kao/article/details/133793189