-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #436 from GIScience/filter-geometries
[oshdb-filter] add additional geometry based filters
- Loading branch information
Showing
14 changed files
with
1,033 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
oshdb-filter/src/main/java/org/heigit/ohsome/oshdb/filter/GeometryFilterInnerRings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.heigit.ohsome.oshdb.filter; | ||
|
||
import javax.annotation.Nonnull; | ||
import org.locationtech.jts.geom.Geometry; | ||
import org.locationtech.jts.geom.MultiPolygon; | ||
import org.locationtech.jts.geom.Polygon; | ||
|
||
/** | ||
* A filter which checks the number of inner rings of a multipolygon relation. | ||
*/ | ||
public class GeometryFilterInnerRings extends GeometryFilter { | ||
/** | ||
* Creates a new inner rings filter object. | ||
* | ||
* @param range the allowed range (inclusive) of values to pass the filter | ||
*/ | ||
public GeometryFilterInnerRings(@Nonnull ValueRange range) { | ||
super(range, GeometryMetricEvaluator.fromLambda(GeometryFilterInnerRings::countInnerRings, | ||
"geometry.inners")); | ||
} | ||
|
||
private static int countInnerRings(Geometry geometry) { | ||
if (geometry instanceof Polygon) { | ||
return ((Polygon) geometry).getNumInteriorRing(); | ||
} else if (geometry instanceof MultiPolygon) { | ||
var counter = 0; | ||
for (var i = 0; i < geometry.getNumGeometries(); i++) { | ||
counter += ((Polygon) geometry.getGeometryN(i)).getNumInteriorRing(); | ||
} | ||
return counter; | ||
} else { | ||
return -1; | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
oshdb-filter/src/main/java/org/heigit/ohsome/oshdb/filter/GeometryFilterOuterRings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.heigit.ohsome.oshdb.filter; | ||
|
||
import javax.annotation.Nonnull; | ||
import org.locationtech.jts.geom.Polygonal; | ||
|
||
/** | ||
* A filter which checks the number of outer rings of a multipolygon relation. | ||
*/ | ||
public class GeometryFilterOuterRings extends GeometryFilter { | ||
/** | ||
* Creates a new outer rings filter object. | ||
* | ||
* @param range the allowed range (inclusive) of values to pass the filter | ||
*/ | ||
public GeometryFilterOuterRings(@Nonnull ValueRange range) { | ||
super(range, GeometryMetricEvaluator.fromLambda(geometry -> | ||
geometry instanceof Polygonal ? geometry.getNumGeometries() : -1, | ||
"geometry.outers")); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
oshdb-filter/src/main/java/org/heigit/ohsome/oshdb/filter/GeometryFilterPerimeter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.heigit.ohsome.oshdb.filter; | ||
|
||
import javax.annotation.Nonnull; | ||
import org.heigit.ohsome.oshdb.util.geometry.Geo; | ||
import org.locationtech.jts.geom.Polygonal; | ||
|
||
/** | ||
* A filter which checks the perimeter of polygonal OSM feature geometries. | ||
*/ | ||
public class GeometryFilterPerimeter extends GeometryFilter { | ||
/** | ||
* Creates a new perimeter filter object. | ||
* | ||
* @param range the allowed range (inclusive) of values to pass the filter | ||
*/ | ||
public GeometryFilterPerimeter(@Nonnull ValueRange range) { | ||
super(range, GeometryMetricEvaluator.fromLambda(geometry -> { | ||
if (!(geometry instanceof Polygonal)) { | ||
return 0; | ||
} | ||
var boundary = geometry.getBoundary(); | ||
return Geo.lengthOf(boundary); | ||
}, "perimeter")); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
oshdb-filter/src/main/java/org/heigit/ohsome/oshdb/filter/GeometryFilterRoundness.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.heigit.ohsome.oshdb.filter; | ||
|
||
import javax.annotation.Nonnull; | ||
import org.heigit.ohsome.oshdb.util.geometry.Geo; | ||
|
||
/** | ||
* A filter which checks the roundness of polygonal OSM feature geometries. | ||
* | ||
* <p>Uses the Polsby-Popper test score, see | ||
* <a href="https://en.wikipedia.org/wiki/Polsby%E2%80%93Popper_test">wikipedia</a> for details.</p> | ||
*/ | ||
public class GeometryFilterRoundness extends GeometryFilter { | ||
/** | ||
* Creates a new "roundness" filter object. | ||
* | ||
* @param range the allowed range (inclusive) of values to pass the filter | ||
*/ | ||
public GeometryFilterRoundness(@Nonnull ValueRange range) { | ||
super(range, GeometryMetricEvaluator.fromLambda(Geo::roundness, "geometry.roundness")); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
oshdb-filter/src/main/java/org/heigit/ohsome/oshdb/filter/GeometryFilterSquareness.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.heigit.ohsome.oshdb.filter; | ||
|
||
import javax.annotation.Nonnull; | ||
import org.heigit.ohsome.oshdb.util.geometry.Geo; | ||
|
||
/** | ||
* A filter which checks the squareness of OSM feature geometries. | ||
* | ||
* <p>For the measure for the rectilinearity (or squareness) of a geometry, a methods adapted from the | ||
* paper "A Rectilinearity Measurement for Polygons" by Joviša Žunić and Paul L. Rosin | ||
* (DOI:10.1007/3-540-47967-8_50, https://link.springer.com/chapter/10.1007%2F3-540-47967-8_50, | ||
* https://www.researchgate.net/publication/221304067_A_Rectilinearity_Measurement_for_Polygons) is used.</p> | ||
*/ | ||
public class GeometryFilterSquareness extends GeometryFilter { | ||
/** | ||
* Creates a new squareness filter object. | ||
* | ||
* @param range the allowed range (inclusive) of values to pass the filter | ||
*/ | ||
public GeometryFilterSquareness(@Nonnull ValueRange range) { | ||
super(range, GeometryMetricEvaluator.fromLambda(Geo::squareness, "squareness")); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
oshdb-filter/src/main/java/org/heigit/ohsome/oshdb/filter/GeometryFilterVertices.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.heigit.ohsome.oshdb.filter; | ||
|
||
import javax.annotation.Nonnull; | ||
import org.locationtech.jts.geom.Geometry; | ||
|
||
/** | ||
* A filter which checks the number of vertices of OSM feature geometries. | ||
*/ | ||
public class GeometryFilterVertices extends GeometryFilter { | ||
public GeometryFilterVertices(@Nonnull ValueRange range) { | ||
super(range, GeometryMetricEvaluator.fromLambda(Geometry::getNumPoints, "geometry.vertices")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.