Skip to content

Commit

Permalink
Merge pull request #54 from GeoWerkstatt/fix-union
Browse files Browse the repository at this point in the history
Fix unexpected Error while calculating Union
  • Loading branch information
patrickackermann authored May 29, 2024
2 parents eb9a91d + 96ab20e commit 99dc528
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ private IomObject union(UnionSurfaceKey key) {
.toArray(MultiPolygon[]::new);

Geometry geometryCollection = new GeometryFactory().createGeometryCollection(polygons);
Geometry unionGeometry = geometryCollection.union();

// 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 {
if (unionGeometry instanceof Polygon) {
Expand Down
22 changes: 22 additions & 0 deletions src/test/data/Union/UnionTest.ili
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
INTERLIS 2.4;

MODEL TestSuite
AT "mailto:[email protected]" 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.
179 changes: 179 additions & 0 deletions src/test/data/Union/UnionTest.xtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?xml version="1.0" encoding="UTF-8"?>
<ili:transfer xmlns:ili="http://www.interlis.ch/xtf/2.4/INTERLIS"
xmlns:geom="http://www.interlis.ch/geometry/1.0"
xmlns:TestSuite="http://www.interlis.ch/xtf/2.4/TestSuite">
<ili:headersection>
<ili:models>
<ili:model>GeoW_FunctionsExt</ili:model>
<ili:model>TestSuite</ili:model>
</ili:models>
</ili:headersection>
<ili:datasection>
<TestSuite:FunctionTestTopic ili:bid="TestSuite.FunctionTestTopic">
<TestSuite:UnionTest ili:tid="52197431-4822-4faf-9379-4ad382d87d87">
<TestSuite:geometry>
<geom:surface>
<geom:exterior>
<geom:polyline>
<geom:coord>
<geom:c1>2682807</geom:c1>
<geom:c2>1216895</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2682795</geom:c1>
<geom:c2>1216885</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2682795</geom:c1>
<geom:c2>1216919</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2682807</geom:c1>
<geom:c2>1216895</geom:c2>
</geom:coord>
</geom:polyline>
</geom:exterior>
</geom:surface>
</TestSuite:geometry>
</TestSuite:UnionTest>
<TestSuite:UnionTest ili:tid="1f1e4f26-31fd-4e55-97f0-97b04ba218d5">
<TestSuite:geometry>
<geom:surface>
<geom:exterior>
<geom:polyline>
<geom:coord>
<geom:c1>2682323.1119999997</geom:c1>
<geom:c2>1216563.0929999985</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2682532.8150000013</geom:c1>
<geom:c2>1216383.9310000017</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2682355.9409999996</geom:c1>
<geom:c2>1216436.9279999994</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2682323.1119999997</geom:c1>
<geom:c2>1216563.0929999985</geom:c2>
</geom:coord>
</geom:polyline>
</geom:exterior>
</geom:surface>
</TestSuite:geometry>
</TestSuite:UnionTest>
<TestSuite:UnionTest ili:tid="35c6eb69-131f-41fe-8d05-9c283be9f052">
<TestSuite:geometry>
<geom:surface>
<geom:exterior>
<geom:polyline>
<geom:coord>
<geom:c1>2682541.671</geom:c1>
<geom:c2>1216376.2459999993</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2682532.8150000013</geom:c1>
<geom:c2>1216383.9310000017</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2682549.9239999987</geom:c1>
<geom:c2>1216395.3790000007</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2682541.671</geom:c1>
<geom:c2>1216376.2459999993</geom:c2>
</geom:coord>
</geom:polyline>
</geom:exterior>
</geom:surface>
</TestSuite:geometry>
</TestSuite:UnionTest>
<TestSuite:UnionTest ili:tid="4ca0bff8-a14a-4afe-8ab8-f480085b8fa2">
<TestSuite:geometry>
<geom:surface>
<geom:exterior>
<geom:polyline>
<geom:coord>
<geom:c1>2684079.278000001</geom:c1>
<geom:c2>1219403.2149999999</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2683622.9990000017</geom:c1>
<geom:c2>1219514.1849999987</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2683781.8209999986</geom:c1>
<geom:c2>1219698.3060000017</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2684079.278000001</geom:c1>
<geom:c2>1219403.2149999999</geom:c2>
</geom:coord>
</geom:polyline>
</geom:exterior>
</geom:surface>
</TestSuite:geometry>
</TestSuite:UnionTest>
<TestSuite:UnionTest ili:tid="937f9d8b-b5bf-4d1a-865a-a3a9e99d5a42">
<TestSuite:geometry>
<geom:surface>
<geom:exterior>
<geom:polyline>
<geom:coord>
<geom:c1>2682897.403999999</geom:c1>
<geom:c2>1218167.2280000001</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2683428.9990000017</geom:c1>
<geom:c2>1217208.4189999998</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2683200</geom:c1>
<geom:c2>1217201</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2682360</geom:c1>
<geom:c2>1218110</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2682897.403999999</geom:c1>
<geom:c2>1218167.2280000001</geom:c2>
</geom:coord>
</geom:polyline>
</geom:exterior>
</geom:surface>
</TestSuite:geometry>
</TestSuite:UnionTest>
<TestSuite:UnionTest ili:tid="d79e8d9a-0f6a-4ce9-a65b-a24d76117dd0">
<TestSuite:geometry>
<geom:surface>
<geom:exterior>
<geom:polyline>
<geom:coord>
<geom:c1>2683548.8319999985</geom:c1>
<geom:c2>1217497.7049999982</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2683402.909000002</geom:c1>
<geom:c2>1216556.5390000008</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2683200</geom:c1>
<geom:c2>1217201</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2683428.9990000017</geom:c1>
<geom:c2>1217208.4189999998</geom:c2>
</geom:coord>
<geom:coord>
<geom:c1>2683548.8319999985</geom:c1>
<geom:c2>1217497.7049999982</geom:c2>
</geom:coord>
</geom:polyline>
</geom:exterior>
</geom:surface>
</TestSuite:geometry>
</TestSuite:UnionTest>
</TestSuite:FunctionTestTopic>
</ili:datasection>
</ili:transfer>
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 99dc528

Please sign in to comment.