From 526220b8d1fd94e4d79f27b3343a5bb55c8e3ae8 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Wed, 2 May 2018 08:20:51 -0700 Subject: [PATCH] Sink Island Check Enhancements (#36) * Update to remove edges with end node equal to certain amenity types * Initial logic for Sink Island Enhancements * Added peek logic to remove amenity type edge; * Moved condition to exclude end nodes with certain amenity types to very end * Use valid edge to filter, and modify check for end node having amentity tag value * Update to unit test and dependencies * Remove unnecessary lines in flag --- dependencies.gradle | 2 +- .../linear/edges/SinkIslandCheck.java | 38 +++++++++++++++++-- .../linear/edges/SinkIslandCheckTest.java | 9 +++++ .../linear/edges/SinkIslandCheckTestRule.java | 12 ++++++ 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index 67f646309..8d1cbf286 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,6 +1,6 @@ project.ext.versions = [ checkstyle: '7.6.1', - atlas: '5.0.12', + atlas: '5.0.14', commons:'2.6', atlas_generator: '4.0.4', ] diff --git a/src/main/java/org/openstreetmap/atlas/checks/validation/linear/edges/SinkIslandCheck.java b/src/main/java/org/openstreetmap/atlas/checks/validation/linear/edges/SinkIslandCheck.java index 9eef0cdf4..419f2efe6 100644 --- a/src/main/java/org/openstreetmap/atlas/checks/validation/linear/edges/SinkIslandCheck.java +++ b/src/main/java/org/openstreetmap/atlas/checks/validation/linear/edges/SinkIslandCheck.java @@ -2,6 +2,7 @@ import java.util.ArrayDeque; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Optional; @@ -14,7 +15,9 @@ import org.openstreetmap.atlas.checks.flag.CheckFlag; import org.openstreetmap.atlas.geography.atlas.items.AtlasObject; import org.openstreetmap.atlas.geography.atlas.items.Edge; +import org.openstreetmap.atlas.geography.atlas.items.Node; import org.openstreetmap.atlas.tags.AerowayTag; +import org.openstreetmap.atlas.tags.AmenityTag; import org.openstreetmap.atlas.tags.HighwayTag; import org.openstreetmap.atlas.tags.RouteTag; import org.openstreetmap.atlas.tags.SyntheticBoundaryNodeTag; @@ -28,13 +31,19 @@ * @author matthieun * @author cuthbertm * @author gpogulsky + * @author savannahostrowski */ public class SinkIslandCheck extends BaseCheck { - public static final float LOAD_FACTOR = 0.8f; - public static final long TREE_SIZE_DEFAULT = 50; - private static final List FALLBACK_INSTRUCTIONS = Arrays - .asList("Road is impossible to get out of."); + private static final float LOAD_FACTOR = 0.8f; + private static final long TREE_SIZE_DEFAULT = 50; + private static final List FALLBACK_INSTRUCTIONS = Collections + .singletonList("Road is impossible to get out of."); + private static final String MOTORCYCLE_PARKING_AMENITY = "MOTORCYCLE_PARKING"; + private static final String PARKING_ENTRANCE_AMENITY = "PARKING_ENTRANCE"; + private static final List amenityValuesToExclude = Arrays.asList( + AmenityTag.PARKING.toString(), AmenityTag.PARKING_SPACE.toString(), + MOTORCYCLE_PARKING_AMENITY, PARKING_ENTRANCE_AMENITY); private static final long serialVersionUID = -1432150496331502258L; private final int storeSize; private final int treeSize; @@ -171,6 +180,8 @@ private boolean validEdge(final AtlasObject object) // Ignore any airport taxiways and runways, as these often create a sink island && !Validators.isOfType(object, AerowayTag.class, AerowayTag.TAXIWAY, AerowayTag.RUNWAY) + // Ignore edges that have an amenity tag equal to one of the amenityValuesToExclude + && !endNodeHasAmenityTypeToExclude(object) // Ignore edges that have been way sectioned at the border, as has high probability // of creating a false positive due to the sectioning of the way && !(SyntheticBoundaryNodeTag.isBoundaryNode(((Edge) object).end()) @@ -180,4 +191,23 @@ private boolean validEdge(final AtlasObject object) // Ignore any highways tagged as areas && !TagPredicates.IS_AREA.test(object); } + + /** + * This function checks to see if the end node of an Edge AtlasObject has an amenity tag with + * one of the amenityValuesToExclude. + * + * @param object + * An AtlasObject (known to be an Edge) + * @return {@code true} if the end node of the end has one of the amenityValuesToExclude, and + * {@code false} otherwise + */ + private boolean endNodeHasAmenityTypeToExclude(final AtlasObject object) + { + final Edge edge = (Edge) object; + final Node endNode = edge.end(); + + return Validators.isOfType(endNode, AmenityTag.class, AmenityTag.PARKING, + AmenityTag.PARKING_SPACE, AmenityTag.MOTORCYCLE_PARKING, + AmenityTag.PARKING_ENTRANCE); + } } diff --git a/src/test/java/org/openstreetmap/atlas/checks/validation/linear/edges/SinkIslandCheckTest.java b/src/test/java/org/openstreetmap/atlas/checks/validation/linear/edges/SinkIslandCheckTest.java index b55bddc04..e59addae9 100644 --- a/src/test/java/org/openstreetmap/atlas/checks/validation/linear/edges/SinkIslandCheckTest.java +++ b/src/test/java/org/openstreetmap/atlas/checks/validation/linear/edges/SinkIslandCheckTest.java @@ -33,4 +33,13 @@ public void testSinkDetection() ConfigurationResolver.inlineConfiguration("{\"SinkIslandCheck.tree.size\": 3}"))); this.verifier.globallyVerify(flags -> Assert.assertEquals(1, flags.size())); } + + @Test + public void testSingleEdgeWithAmenity() + { + this.verifier.actual(this.setup.getSingleEdgeWithAmenityAtlas(), new SinkIslandCheck( + ConfigurationResolver.inlineConfiguration("{\"SinkIslandCheck.tree.size\": 3}"))); + this.verifier.globallyVerify(flags -> Assert.assertEquals(0, flags.size())); + } + } diff --git a/src/test/java/org/openstreetmap/atlas/checks/validation/linear/edges/SinkIslandCheckTestRule.java b/src/test/java/org/openstreetmap/atlas/checks/validation/linear/edges/SinkIslandCheckTestRule.java index 233429f78..b4b42b79a 100644 --- a/src/test/java/org/openstreetmap/atlas/checks/validation/linear/edges/SinkIslandCheckTestRule.java +++ b/src/test/java/org/openstreetmap/atlas/checks/validation/linear/edges/SinkIslandCheckTestRule.java @@ -59,6 +59,13 @@ public class SinkIslandCheckTestRule extends CoreTestRule @Loc(value = TEST_7) }, tags = { "highway=primary", "oneway=yes" }) }) private Atlas singleEdgeAtlas; + @TestAtlas(nodes = { @Node(coordinates = @Loc(value = TEST_6)), + @Node(coordinates = @Loc(value = TEST_7), tags = { "amenity=parking" }) }, + + edges = { @Edge(id = "360978519000003", coordinates = { @Loc(value = TEST_6), + @Loc(value = TEST_7) }, tags = { "highway=primary", "oneway=yes" }) }) + private Atlas singleEdgeWithAmenityAtlas; + public Atlas getSingleEdgeAtlas() { return this.singleEdgeAtlas; @@ -68,4 +75,9 @@ public Atlas getTestAtlas() { return this.testAtlas; } + + public Atlas getSingleEdgeWithAmenityAtlas() + { + return this.singleEdgeWithAmenityAtlas; + } }