-
Notifications
You must be signed in to change notification settings - Fork 19
[oshdb-filter] add additional geometry based filters #436
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
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
66ef217
add perimeter geometry filter
tyrasd c9a3d08
add vertices "numPoints" filter
tyrasd aaccc30
add outers/inners filter + slight adjustment to vertices filter
tyrasd df57a5b
rename inners/outer/vertices filters to have a "geometry." prefix
tyrasd a10af09
add "geometry.roundness" filter
tyrasd 90de004
[WIP] add squareness filter and evaluation method
tyrasd 54c1e62
fix javadocs
tyrasd 5cbe5aa
add new geometry filters to changelog
tyrasd 390a182
add to changelog
tyrasd 456575f
Merge branch 'master' into filter-geometries
tyrasd 86c1b5a
update to junit5
tyrasd 46b5b0a
add test for Geo.compactness method
tyrasd e55aa55
minor fix changelog fixes
tyrasd 78519a1
fix error in brearing calculation, add some more test cases
tyrasd a039832
Merge branch 'master' into filter-geometries
tyrasd c165e37
Apply suggestions from code review
tyrasd 249e53e
drop unused/untested methods, rename methods to match filters
tyrasd 6a1c96b
round input coordinates of test geometry
tyrasd 9e738c2
rename variable to match "positiveIntegerRange"
tyrasd b2d99f3
add todo comment
tyrasd b8d1097
extract method for clarity
tyrasd d168a20
extract often used method combination
tyrasd d88e647
add some (internal) comments
tyrasd d1c1187
test squareness calculation with LineStrings
tyrasd 142ad2a
split and add more tests
tyrasd e9c4076
refactor to deduplicate code
tyrasd 0b29af6
split test cases into nested test class
tyrasd e3cbd47
Merge branch 'master' into filter-geometries
tyrasd b779c7c
(minor) whitespace cleanup
tyrasd c9eb25d
shorten link
tyrasd f8ffd21
add multipolygon test cases for squareness method
tyrasd 28cb88b
Apply suggestions from code review
tyrasd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.