From d2659179f95fd38d4243b4ecf25e6df10ec8d34c Mon Sep 17 00:00:00 2001 From: Patrick Ackermann Date: Wed, 29 May 2024 10:50:14 +0200 Subject: [PATCH 1/3] Add additional Union test This test reproduces https://github.com/GeoWerkstatt/geow-interlis-functions/issues/49 --- src/test/data/Union/UnionTest.ili | 22 +++ src/test/data/Union/UnionTest.xtf | 179 ++++++++++++++++++ .../functions/UnionIoxPluginTest.java | 6 + 3 files changed, 207 insertions(+) create mode 100644 src/test/data/Union/UnionTest.ili create mode 100644 src/test/data/Union/UnionTest.xtf diff --git a/src/test/data/Union/UnionTest.ili b/src/test/data/Union/UnionTest.ili new file mode 100644 index 0000000..d6dddba --- /dev/null +++ b/src/test/data/Union/UnionTest.ili @@ -0,0 +1,22 @@ +INTERLIS 2.4; + +MODEL TestSuite + AT "mailto:info@geowerkstatt.ch" VERSION "2020_01_15" = + IMPORTS GeoW_FunctionsExt; + + DOMAIN + !!@CRS=EPSG:2056 + Coord2 = COORD + 2460000.000 .. 2870000.000, + 1045000.000 .. 1310000.000, + ROTATION 2 -> 1; + + TOPIC FunctionTestTopic = + CLASS UnionTest = + geometry : MANDATORY AREA WITH (ARCS,STRAIGHTS) VERTEX Coord2 WITHOUT OVERLAPS > 0.05; + + SET CONSTRAINT GeoW_FunctionsExt.GetInnerRingsCount(GeoW_FunctionsExt.Union(ALL,"geometry"), UNDEFINED) == 0; + END UnionTest; + END FunctionTestTopic; + +END TestSuite. diff --git a/src/test/data/Union/UnionTest.xtf b/src/test/data/Union/UnionTest.xtf new file mode 100644 index 0000000..5a2760f --- /dev/null +++ b/src/test/data/Union/UnionTest.xtf @@ -0,0 +1,179 @@ + + + + + GeoW_FunctionsExt + TestSuite + + + + + + + + + + + 2682807 + 1216895 + + + 2682795 + 1216885 + + + 2682795 + 1216919 + + + 2682807 + 1216895 + + + + + + + + + + + + + 2682323.1119999997 + 1216563.0929999985 + + + 2682532.8150000013 + 1216383.9310000017 + + + 2682355.9409999996 + 1216436.9279999994 + + + 2682323.1119999997 + 1216563.0929999985 + + + + + + + + + + + + + 2682541.671 + 1216376.2459999993 + + + 2682532.8150000013 + 1216383.9310000017 + + + 2682549.9239999987 + 1216395.3790000007 + + + 2682541.671 + 1216376.2459999993 + + + + + + + + + + + + + 2684079.278000001 + 1219403.2149999999 + + + 2683622.9990000017 + 1219514.1849999987 + + + 2683781.8209999986 + 1219698.3060000017 + + + 2684079.278000001 + 1219403.2149999999 + + + + + + + + + + + + + 2682897.403999999 + 1218167.2280000001 + + + 2683428.9990000017 + 1217208.4189999998 + + + 2683200 + 1217201 + + + 2682360 + 1218110 + + + 2682897.403999999 + 1218167.2280000001 + + + + + + + + + + + + + 2683548.8319999985 + 1217497.7049999982 + + + 2683402.909000002 + 1216556.5390000008 + + + 2683200 + 1217201 + + + 2683428.9990000017 + 1217208.4189999998 + + + 2683548.8319999985 + 1217497.7049999982 + + + + + + + + + diff --git a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/UnionIoxPluginTest.java b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/UnionIoxPluginTest.java index 1d5bec7..ef155e6 100644 --- a/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/UnionIoxPluginTest.java +++ b/src/test/java/ch/geowerkstatt/ilivalidator/extensions/functions/UnionIoxPluginTest.java @@ -34,4 +34,10 @@ void mandatoryConstraintMergedInnerRings() throws Ili2cFailure, IoxException { AssertionHelper.assertNoConstraintError(vh, "innerRings"); AssertionHelper.assertNoConstraintError(vh, "innerRingsUnion"); } + + @Test + void test() throws Exception { + vh.runValidation(new String[]{"Union/UnionTest.xtf"}, new String[]{"Union/UnionTest.ili"}); + Assert.equals(0, vh.getErrs().size()); + } } From 218fda9d94ed46b69c6dd5c6c4a2249818c28fda Mon Sep 17 00:00:00 2001 From: Patrick Ackermann Date: Wed, 29 May 2024 10:53:32 +0200 Subject: [PATCH 2/3] Calculate Union with buffer(0) Geometry.union() fails to calculate the union in some edge cases --- .../ilivalidator/extensions/functions/UnionIoxPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/UnionIoxPlugin.java b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/UnionIoxPlugin.java index d63c783..da055aa 100644 --- a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/UnionIoxPlugin.java +++ b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/UnionIoxPlugin.java @@ -65,7 +65,7 @@ private IomObject union(UnionSurfaceKey key) { .toArray(MultiPolygon[]::new); Geometry geometryCollection = new GeometryFactory().createGeometryCollection(polygons); - Geometry unionGeometry = geometryCollection.union(); + Geometry unionGeometry = geometryCollection.buffer(0); try { if (unionGeometry instanceof Polygon) { From 96ab20e74f91eee88462b14e186cc272e4bd1546 Mon Sep 17 00:00:00 2001 From: Patrick Ackermann Date: Wed, 29 May 2024 12:15:01 +0200 Subject: [PATCH 3/3] Explain change in comment --- .../ilivalidator/extensions/functions/UnionIoxPlugin.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/UnionIoxPlugin.java b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/UnionIoxPlugin.java index da055aa..e3f955e 100644 --- a/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/UnionIoxPlugin.java +++ b/src/main/java/ch/geowerkstatt/ilivalidator/extensions/functions/UnionIoxPlugin.java @@ -65,6 +65,9 @@ private IomObject union(UnionSurfaceKey key) { .toArray(MultiPolygon[]::new); Geometry geometryCollection = new GeometryFactory().createGeometryCollection(polygons); + + // Calculating unionGeometry with Geometry.union() in JTS 1.14.0 may cause unexpected Exception + // See: https://github.com/GeoWerkstatt/geow-interlis-functions/issues/49 Geometry unionGeometry = geometryCollection.buffer(0); try {