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

报错信息如下:

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

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

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

        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

 

  • 6
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值