From af4eae44923071b950acc5fe2f7184bd863ab03a Mon Sep 17 00:00:00 2001 From: Martin Davis Date: Wed, 8 Nov 2023 09:20:05 -0800 Subject: [PATCH] Fix predicates for MultiPoint with EMPTY --- .../jts/algorithm/PointLocator.java | 3 +++ .../jts/geomgraph/GeometryGraph.java | 4 ++- .../jts/operation/relate/RelateTest.java | 6 +++++ .../testxml/general/TestRelatePA.xml | 25 +++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/modules/core/src/main/java/org/locationtech/jts/algorithm/PointLocator.java b/modules/core/src/main/java/org/locationtech/jts/algorithm/PointLocator.java index 3e2f469463..0a08fad14a 100644 --- a/modules/core/src/main/java/org/locationtech/jts/algorithm/PointLocator.java +++ b/modules/core/src/main/java/org/locationtech/jts/algorithm/PointLocator.java @@ -107,6 +107,9 @@ else if (geom instanceof Polygon) { private void computeLocation(Coordinate p, Geometry geom) { + if (geom.isEmpty()) + return; + if (geom instanceof Point) { updateLocationInfo(locateOnPoint(p, (Point) geom)); } diff --git a/modules/core/src/main/java/org/locationtech/jts/geomgraph/GeometryGraph.java b/modules/core/src/main/java/org/locationtech/jts/geomgraph/GeometryGraph.java index 6e3f824ef9..4292399a88 100644 --- a/modules/core/src/main/java/org/locationtech/jts/geomgraph/GeometryGraph.java +++ b/modules/core/src/main/java/org/locationtech/jts/geomgraph/GeometryGraph.java @@ -222,7 +222,9 @@ private void addCollection(GeometryCollection gc) { for (int i = 0; i < gc.getNumGeometries(); i++) { Geometry g = gc.getGeometryN(i); - add(g); + if (! g.isEmpty()) { + add(g); + } } } /** diff --git a/modules/core/src/test/java/org/locationtech/jts/operation/relate/RelateTest.java b/modules/core/src/test/java/org/locationtech/jts/operation/relate/RelateTest.java index 8b7ee3e872..51975ea0be 100644 --- a/modules/core/src/test/java/org/locationtech/jts/operation/relate/RelateTest.java +++ b/modules/core/src/test/java/org/locationtech/jts/operation/relate/RelateTest.java @@ -101,6 +101,12 @@ public void testIntersectsSnappedEndpoint2() runRelateTest(a, b, "FF10F0102" ); } + public void testMultiPointWithEmpty() + { + String a = "MULTIPOINT(EMPTY,(0 0))"; + String b = "POLYGON ((1 0,0 1,-1 0,0 -1, 1 0))"; + runRelateTest(a, b, "0FFFFF212" ); + } void runRelateTest(String wkt1, String wkt2, String expectedIM) { diff --git a/modules/tests/src/test/resources/testxml/general/TestRelatePA.xml b/modules/tests/src/test/resources/testxml/general/TestRelatePA.xml index 7d9e4c5376..35a6f75bf9 100644 --- a/modules/tests/src/test/resources/testxml/general/TestRelatePA.xml +++ b/modules/tests/src/test/resources/testxml/general/TestRelatePA.xml @@ -100,4 +100,29 @@ + + mPA - empty Point element + + MULTIPOINT(EMPTY,(0 0)) + + + POLYGON ((1 0,0 1,-1 0,0 -1, 1 0)) + + + + true + + + false + true + false + false + false + false + true + false + false + true + +