【GeoTools】geotools空间分析存在自相交情况时的错误解决

报错信息如下:

org.locationtech.jts.geom.TopologyException: found non-noded intersection between LINESTRING ( 115.081751296 22.877495404, 115.08235485099999 22.877178259000004 )......

查看多边形发现存在自相交的情况:

【GeoTools】geotools空间分析存在自相交情况时的错误解决_第1张图片

解决办法:自己和自己做一次叠加分析,将返回结果再和其它多边形进行叠加分析。

        GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
        WKTReader reader = new WKTReader(geometryFactory);
        String wktPolygon1 = "POLYGON((115.056659208438 22.8705758182769, 115.056659208438 22.8630881201852, 115.075378453668 22.8630881201852, 115.073267702012 22.8676901910949, 115.064758191781 22.8712427237672, 115.060642026572 22.8712427237672, 115.056659208438 22.8705758182769))";
        Geometry geometry1 = reader.read(wktPolygon1);
        // 图形存在自相交的情况
        String wktPolygon2 = "MULTIPOLYGON (((115.081751296 22.877495404, 115.08235485099999 22.877178259000004, 115.08187908699995 22.877199625000003, 115.08186948800005 22.877064256999972, 115.08234682600005 22.877049725000006, 115.08235485099999 22.877178259000004, 115.08253756700003 22.87708225, 115.081394789 22.876617703000022, 115.081393606 22.876618759999985, 115.08134342999995 22.876644435999992, 115.08130771200001 22.876678020999975, 115.08127786700004 22.87672623200001, 115.08107261099997 22.87712563399998, 115.08103419400004 22.877173486000004, 115.08102423900004 22.877191219999986, 115.08102438699996 22.877209929999992, 115.08103463199996 22.87722856900001, 115.08104820799997 22.87724302999999, 115.08118117100003 22.877315925000005, 115.08137075299999 22.87741251800003, 115.081543839 22.877451877999988, 115.08165843200004 22.877471886000023, 115.08169104499996 22.877482059999977, 115.081751296 22.877495404)))";
        Geometry geometry2 = reader.read(wktPolygon2);
        // 自相交
        Geometry geometry2IntersectGeometry2 = geometry2.intersection(geometry2);
        Geometry geometry1IntersectGeometry2 = geometry1.intersection(geometry2IntersectGeometry2);
        System.out.println(geometry1IntersectGeometry2);

参考文章:

1,Java Geometry计算轨迹与围栏交集效率测试及异常处理

https://blog.csdn.net/boonya/article/details/89361878

 

你可能感兴趣的:(GeoTools)