Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GeometryFixer to use isKeepCollapsed flag for GCs #790

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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