From 516f2d7854db706eedf4054c55da6c7116d3edad Mon Sep 17 00:00:00 2001 From: Martin Davis Date: Wed, 29 Nov 2023 10:14:35 -0800 Subject: [PATCH] Fix InteriorPoint for MultiLineString with EMPTY --- .../jts/algorithm/InteriorPointLine.java | 6 ++++++ .../jts/algorithm/InteriorPointTest.java | 4 ++++ .../testxml/general/TestInteriorPoint.xml | 20 ++++++++++++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/modules/core/src/main/java/org/locationtech/jts/algorithm/InteriorPointLine.java b/modules/core/src/main/java/org/locationtech/jts/algorithm/InteriorPointLine.java index ca5a9832d4..0594a4817f 100644 --- a/modules/core/src/main/java/org/locationtech/jts/algorithm/InteriorPointLine.java +++ b/modules/core/src/main/java/org/locationtech/jts/algorithm/InteriorPointLine.java @@ -69,6 +69,9 @@ public Coordinate getInteriorPoint() */ private void addInterior(Geometry geom) { + if (geom.isEmpty()) + return; + if (geom instanceof LineString) { addInterior(geom.getCoordinates()); } @@ -93,6 +96,9 @@ private void addInterior(Coordinate[] pts) */ private void addEndpoints(Geometry geom) { + if (geom.isEmpty()) + return; + if (geom instanceof LineString) { addEndpoints(geom.getCoordinates()); } diff --git a/modules/core/src/test/java/org/locationtech/jts/algorithm/InteriorPointTest.java b/modules/core/src/test/java/org/locationtech/jts/algorithm/InteriorPointTest.java index bed933f7fe..52aee7761d 100644 --- a/modules/core/src/test/java/org/locationtech/jts/algorithm/InteriorPointTest.java +++ b/modules/core/src/test/java/org/locationtech/jts/algorithm/InteriorPointTest.java @@ -50,6 +50,10 @@ public void testPolygonZeroArea() { checkInteriorPoint(read("POLYGON ((10 10, 10 10, 10 10, 10 10))"), new Coordinate(10, 10)); } + public void testMultiLineWithEmpty() { + checkInteriorPoint(read("MULTILINESTRING ((0 0, 1 1), EMPTY)"), new Coordinate(0, 0)); + } + public void testAll() throws Exception { checkInteriorPointFile(TestFiles.getResourceFilePath("world.wkt")); diff --git a/modules/tests/src/test/resources/testxml/general/TestInteriorPoint.xml b/modules/tests/src/test/resources/testxml/general/TestInteriorPoint.xml index 9c3cbdc05b..b6450dbd0f 100644 --- a/modules/tests/src/test/resources/testxml/general/TestInteriorPoint.xml +++ b/modules/tests/src/test/resources/testxml/general/TestInteriorPoint.xml @@ -1,5 +1,4 @@ - P - empty @@ -38,7 +37,7 @@ L - linestring with single segment LINESTRING (0 0, 7 14) - POINT (7 14) + POINT (0 0) @@ -68,6 +67,13 @@ POINT (180 200) + + mL - multilinestring with empty + MULTILINESTRING ((0 0, 1 1), EMPTY) + + POINT (0 0) + + A - box POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0)) @@ -93,7 +99,7 @@ A - polygon with horizontal segment at centre (narrower L shape) POLYGON ((0 2, 0 4, 3 4, 3 0, 2 0, 2 2, 0 2)) - POINT (2 3) + POINT (1.5 3) @@ -103,6 +109,14 @@ POINT (115 200) + + + mA - multipolygon with empty + MULTIPOLYGON (((0 2, 0 4, 3 4, 3 0, 2 0, 2 2, 0 2)), EMPTY) + + POINT (1.5 3) + + GC - collection of polygons, lines, points GEOMETRYCOLLECTION (POLYGON ((0 40, 40 40, 40 0, 0 0, 0 40)),