Skip to content

Commit

Permalink
Fix GeometryFixer to use isKeepCollapsed flag for GCs (#790)
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
  • Loading branch information
dr-jts committed Oct 26, 2021
1 parent 45a6deb commit 5128092
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* <p>
* Input geometries are always processed, so even valid inputs may
* have some minor alterations. The output is always a new geometry object.
*
* <h2>Semantic Rules</h2>
* <ol>
* <li>Vertices with non-finite X or Y ordinates are removed
Expand All @@ -62,7 +63,8 @@
* <li>Collapsed lines and polygons are handled as follows,
* depending on the <code>keepCollapsed</code> setting:
* <ul>
* <li><code>false</code>: (default) collapses are converted to empty geometries</li>
* <li><code>false</code>: (default) collapses are converted to empty geometries
* (and removed if they are elements of collections)</li>
* <li><code>true</code>: collapses are converted to a valid geometry of lower dimension</li>
* </ul>
* </li>
Expand Down Expand Up @@ -375,8 +377,14 @@ private Geometry fixMultiPolygon(MultiPolygon geom) {
private Geometry fixCollection(GeometryCollection geom) {
Geometry[] geomRep = new Geometry[geom.getNumGeometries()];
for (int i = 0; i < geom.getNumGeometries(); i++) {
geomRep[i] = fix(geom.getGeometryN(i));
geomRep[i] = fix(geom.getGeometryN(i), isKeepCollapsed);
}
return factory.createGeometryCollection(geomRep);
}

private static Geometry fix(Geometry geom, boolean isKeepCollapsed) {
GeometryFixer fix = new GeometryFixer(geom);
fix.setKeepCollapsed(isKeepCollapsed);
return fix.getResult();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,21 @@ public void testGCWithAllEmpty() {
"GEOMETRYCOLLECTION (POINT EMPTY, LINESTRING EMPTY, POLYGON EMPTY)");
}

public void testGCKeepCollapse() {
checkFixKeepCollapse("GEOMETRYCOLLECTION (LINESTRING ( 0 0, 0 0), POINT (1 1))",
"GEOMETRYCOLLECTION (POINT (0 0), POINT (1 1))");
}

//----------------------------------------

public void testPolygonZBowtie() {
checkFixZ("POLYGON Z ((10 90 1, 90 10 9, 90 90 9, 10 10 1, 10 90 1))",
"MULTIPOLYGON Z(((10 10 1, 10 90 1, 50 50 5, 10 10 1)), ((50 50 5, 90 90 9, 90 10 9, 50 50 5)))");
"MULTIPOLYGON Z (((10 10 1, 10 90 1, 50 50 5, 10 10 1)), ((50 50 5, 90 90 9, 90 10 9, 50 50 5)))");
}

public void testPolygonZHoleOverlap() {
checkFixZ("POLYGON Z ((10 90 1, 60 90 6, 60 10 6, 10 10 1, 10 90 1), (20 80 2, 90 80 9, 90 20 9, 20 20 2, 20 80 2))",
"POLYGON Z((10 10 1, 10 90 1, 60 90 6, 60 80 6, 20 80 2, 20 20 2, 60 20 6, 60 10 6, 10 10 1))");
"POLYGON Z ((10 10 1, 10 90 1, 60 90 6, 60 80 6, 20 80 2, 20 20 2, 60 20 6, 60 10 6, 10 10 1))");
}

public void testMultiLineStringZKeepCollapse() {
Expand Down

0 comments on commit 5128092

Please sign in to comment.