JTS TopologyException 问题

计算2个几何相交结果时候,报错了:
val geometry = polygon.intersection(lineString)
日志如下
org.locationtech.jts.geom.TopologyException: found non-noded intersection between LINESTRING ( 1.352237191719381E7 3623890.160213779, 1.3522371711949987E7 3623889.580561515 ) and LINESTRING ( 1.3522371378318693E7 3623889.936883858, 1.3522376536017932E7 3623888.3707740055 ) [ (1.3522371793480815E7, 3623889.810821934, NaN) ]
    at org.locationtech.jts.noding.FastNodingValidator.checkValid(FastNodingValidator.java:140)
    at org.locationtech.jts.geomgraph.EdgeNodingValidator.checkValid(EdgeNodingValidator.java:81)
    at org.locationtech.jts.geomgraph.EdgeNodingValidator.checkValid(EdgeNodingValidator.java:46)
    at org.locationtech.jts.operation.overlay.OverlayOp.computeOverlay(OverlayOp.java:231)
    at org.locationtech.jts.operation.overlay.OverlayOp.getResultGeometry(OverlayOp.java:183)
    at org.locationtech.jts.operation.overlay.OverlayOp.overlayOp(OverlayOp.java:86)
    at org.locationtech.jts.operation.overlay.snap.SnapIfNeededOverlayOp.getResultGeometry(SnapIfNeededOverlayOp.java:75)
    at org.locationtech.jts.operation.overlay.snap.SnapIfNeededOverlayOp.overlayOp(SnapIfNeededOverlayOp.java:37)
    at org.locationtech.jts.geom.Geometry.intersection(Geometry.java:1354)
......

原因是: polygon (或者 lineString 【另一个图形】)有自相交的情况, 即 invalid

解决办法
        if (!poly.isValid) {
          poly.buffer(0.1)
        }
参考: https://github.com/locationtech/jts/issues/657
posted @ 2022-08-26 16:02  明月照江江  阅读(596)  评论(0编辑  收藏  举报