diff --git a/application/src/main/java/org/opentripplanner/graph_builder/module/osm/SafetyValueNormalizer.java b/application/src/main/java/org/opentripplanner/graph_builder/module/osm/SafetyValueNormalizer.java index 2f070f272c6..2cb5b01dcc6 100644 --- a/application/src/main/java/org/opentripplanner/graph_builder/module/osm/SafetyValueNormalizer.java +++ b/application/src/main/java/org/opentripplanner/graph_builder/module/osm/SafetyValueNormalizer.java @@ -86,8 +86,8 @@ void applyWayProperties( boolean motorVehicleNoThrough = tagMapperForWay.isMotorVehicleThroughTrafficExplicitlyDisallowed( way ); - boolean bicycleNoThrough = tagMapperForWay.isBicycleNoThroughTrafficExplicitlyDisallowed(way); - boolean walkNoThrough = tagMapperForWay.isWalkNoThroughTrafficExplicitlyDisallowed(way); + boolean bicycleNoThrough = tagMapperForWay.isBicycleThroughTrafficExplicitlyDisallowed(way); + boolean walkNoThrough = tagMapperForWay.isWalkThroughTrafficExplicitlyDisallowed(way); if (street != null) { double bicycleSafety = wayData.bicycleSafety().forward(); diff --git a/application/src/main/java/org/opentripplanner/osm/tagmapping/FinlandMapper.java b/application/src/main/java/org/opentripplanner/osm/tagmapping/FinlandMapper.java index 5e413af510a..e9ac9478552 100644 --- a/application/src/main/java/org/opentripplanner/osm/tagmapping/FinlandMapper.java +++ b/application/src/main/java/org/opentripplanner/osm/tagmapping/FinlandMapper.java @@ -8,6 +8,7 @@ import static org.opentripplanner.street.model.StreetTraversalPermission.PEDESTRIAN; import static org.opentripplanner.street.model.StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE; +import java.util.Set; import org.opentripplanner.framework.functional.FunctionUtils.TriFunction; import org.opentripplanner.osm.model.OsmWithTags; import org.opentripplanner.osm.wayproperty.WayPropertySet; @@ -26,6 +27,14 @@ */ class FinlandMapper extends OsmTagMapper { + private static final Set NOTHROUGH_DRIVING_TAGS = Set.of( + "parking_aisle", + "driveway", + "alley", + "emergency_access", + "drive-through" + ); + @Override public void populateProperties(WayPropertySet props) { TriFunction defaultWalkSafetyForPermission = ( @@ -206,7 +215,7 @@ else if (speedLimit <= 16.65f) { } @Override - public boolean isBicycleNoThroughTrafficExplicitlyDisallowed(OsmWithTags way) { + public boolean isBicycleThroughTrafficExplicitlyDisallowed(OsmWithTags way) { String bicycle = way.getTag("bicycle"); return ( isVehicleThroughTrafficExplicitlyDisallowed(way) || @@ -215,8 +224,16 @@ public boolean isBicycleNoThroughTrafficExplicitlyDisallowed(OsmWithTags way) { } @Override - public boolean isWalkNoThroughTrafficExplicitlyDisallowed(OsmWithTags way) { + public boolean isWalkThroughTrafficExplicitlyDisallowed(OsmWithTags way) { String foot = way.getTag("foot"); return isGeneralNoThroughTraffic(way) || doesTagValueDisallowThroughTraffic(foot); } + + @Override + public boolean isMotorVehicleThroughTrafficExplicitlyDisallowed(OsmWithTags way) { + if (super.isMotorVehicleThroughTrafficExplicitlyDisallowed(way)) { + return true; + } + return way.isOneOfTags("service", NOTHROUGH_DRIVING_TAGS); + } } diff --git a/application/src/main/java/org/opentripplanner/osm/tagmapping/OsmTagMapper.java b/application/src/main/java/org/opentripplanner/osm/tagmapping/OsmTagMapper.java index e4c258ccdc4..2df3c22d6a9 100644 --- a/application/src/main/java/org/opentripplanner/osm/tagmapping/OsmTagMapper.java +++ b/application/src/main/java/org/opentripplanner/osm/tagmapping/OsmTagMapper.java @@ -768,7 +768,7 @@ public boolean isMotorVehicleThroughTrafficExplicitlyDisallowed(OsmWithTags way) /** * Returns true if through traffic for bicycle is not allowed. */ - public boolean isBicycleNoThroughTrafficExplicitlyDisallowed(OsmWithTags way) { + public boolean isBicycleThroughTrafficExplicitlyDisallowed(OsmWithTags way) { String bicycle = way.getTag("bicycle"); if (bicycle != null) { return doesTagValueDisallowThroughTraffic(bicycle); @@ -780,7 +780,7 @@ public boolean isBicycleNoThroughTrafficExplicitlyDisallowed(OsmWithTags way) { /** * Returns true if through traffic for walk is not allowed. */ - public boolean isWalkNoThroughTrafficExplicitlyDisallowed(OsmWithTags way) { + public boolean isWalkThroughTrafficExplicitlyDisallowed(OsmWithTags way) { String foot = way.getTag("foot"); if (foot != null) { return doesTagValueDisallowThroughTraffic(foot); diff --git a/application/src/test/java/org/opentripplanner/osm/tagmapping/ConstantSpeedMapperTest.java b/application/src/test/java/org/opentripplanner/osm/tagmapping/ConstantSpeedMapperTest.java new file mode 100644 index 00000000000..6256044320d --- /dev/null +++ b/application/src/test/java/org/opentripplanner/osm/tagmapping/ConstantSpeedMapperTest.java @@ -0,0 +1,23 @@ +package org.opentripplanner.osm.tagmapping; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; +import org.opentripplanner.osm.model.OsmWithTags; + +public class ConstantSpeedMapperTest { + + @Test + public void constantSpeedCarRouting() { + OsmTagMapper osmTagMapper = new ConstantSpeedFinlandMapper(20f); + + var slowWay = new OsmWithTags(); + slowWay.addTag("highway", "residential"); + assertEquals(20f, osmTagMapper.getCarSpeedForWay(slowWay, true)); + + var fastWay = new OsmWithTags(); + fastWay.addTag("highway", "motorway"); + fastWay.addTag("maxspeed", "120 kmph"); + assertEquals(20f, osmTagMapper.getCarSpeedForWay(fastWay, true)); + } +} diff --git a/application/src/test/java/org/opentripplanner/osm/tagmapping/FinlandMapperTest.java b/application/src/test/java/org/opentripplanner/osm/tagmapping/FinlandMapperTest.java index 8e931e1096a..f8b07e06bf6 100644 --- a/application/src/test/java/org/opentripplanner/osm/tagmapping/FinlandMapperTest.java +++ b/application/src/test/java/org/opentripplanner/osm/tagmapping/FinlandMapperTest.java @@ -1,10 +1,12 @@ package org.opentripplanner.osm.tagmapping; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.opentripplanner.street.model.StreetTraversalPermission.NONE; import static org.opentripplanner.street.model.StreetTraversalPermission.PEDESTRIAN; import static org.opentripplanner.street.model.StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.opentripplanner.osm.model.OsmWay; import org.opentripplanner.osm.model.OsmWithTags; @@ -13,12 +15,15 @@ public class FinlandMapperTest { - static WayPropertySet wps = new WayPropertySet(); + private WayPropertySet wps; + private OsmTagMapper mapper; static float epsilon = 0.01f; - static { - var source = new FinlandMapper(); - source.populateProperties(wps); + @BeforeEach + public void setup() { + this.wps = new WayPropertySet(); + this.mapper = new FinlandMapper(); + this.mapper.populateProperties(this.wps); } /** @@ -220,4 +225,12 @@ public void testArea() { wayData = wps.getDataForWay(way); assertEquals(wayData.getPermission(), PEDESTRIAN_AND_BICYCLE); } + + @Test + public void serviceNoThroughTraffic() { + var way = new OsmWay(); + way.addTag("highway", "residential"); + way.addTag("service", "driveway"); + assertTrue(mapper.isMotorVehicleThroughTrafficExplicitlyDisallowed(way)); + } } diff --git a/application/src/test/java/org/opentripplanner/osm/tagmapping/OsmTagMapperTest.java b/application/src/test/java/org/opentripplanner/osm/tagmapping/OsmTagMapperTest.java index aaaf5178d5b..b3ee57f9710 100644 --- a/application/src/test/java/org/opentripplanner/osm/tagmapping/OsmTagMapperTest.java +++ b/application/src/test/java/org/opentripplanner/osm/tagmapping/OsmTagMapperTest.java @@ -34,37 +34,21 @@ public void isMotorThroughTrafficExplicitlyDisallowed() { } @Test - public void constantSpeedCarRouting() { - OsmTagMapper osmTagMapper = new ConstantSpeedFinlandMapper(20f); - - var slowWay = new OsmWithTags(); - slowWay.addTag("highway", "residential"); - assertEquals(20f, osmTagMapper.getCarSpeedForWay(slowWay, true)); - - var fastWay = new OsmWithTags(); - fastWay.addTag("highway", "motorway"); - fastWay.addTag("maxspeed", "120 kmph"); - assertEquals(20f, osmTagMapper.getCarSpeedForWay(fastWay, true)); - } - - @Test - public void isBicycleNoThroughTrafficExplicitlyDisallowed() { + public void isBicycleThroughTrafficExplicitlyDisallowed() { OsmTagMapper osmTagMapper = new OsmTagMapper(); assertTrue( - osmTagMapper.isBicycleNoThroughTrafficExplicitlyDisallowed(way("bicycle", "destination")) + osmTagMapper.isBicycleThroughTrafficExplicitlyDisallowed(way("bicycle", "destination")) ); assertTrue( - osmTagMapper.isBicycleNoThroughTrafficExplicitlyDisallowed(way("access", "destination")) + osmTagMapper.isBicycleThroughTrafficExplicitlyDisallowed(way("access", "destination")) ); } @Test - public void isWalkNoThroughTrafficExplicitlyDisallowed() { + public void isWalkThroughTrafficExplicitlyDisallowed() { OsmTagMapper osmTagMapper = new OsmTagMapper(); - assertTrue(osmTagMapper.isWalkNoThroughTrafficExplicitlyDisallowed(way("foot", "destination"))); - assertTrue( - osmTagMapper.isWalkNoThroughTrafficExplicitlyDisallowed(way("access", "destination")) - ); + assertTrue(osmTagMapper.isWalkThroughTrafficExplicitlyDisallowed(way("foot", "destination"))); + assertTrue(osmTagMapper.isWalkThroughTrafficExplicitlyDisallowed(way("access", "destination"))); } @Test @@ -75,8 +59,8 @@ public void testAccessNo() { tags.addTag("access", "no"); assertTrue(osmTagMapper.isMotorVehicleThroughTrafficExplicitlyDisallowed(tags)); - assertTrue(osmTagMapper.isBicycleNoThroughTrafficExplicitlyDisallowed(tags)); - assertTrue(osmTagMapper.isWalkNoThroughTrafficExplicitlyDisallowed(tags)); + assertTrue(osmTagMapper.isBicycleThroughTrafficExplicitlyDisallowed(tags)); + assertTrue(osmTagMapper.isWalkThroughTrafficExplicitlyDisallowed(tags)); } @Test @@ -87,8 +71,8 @@ public void testAccessPrivate() { tags.addTag("access", "private"); assertTrue(osmTagMapper.isMotorVehicleThroughTrafficExplicitlyDisallowed(tags)); - assertTrue(osmTagMapper.isBicycleNoThroughTrafficExplicitlyDisallowed(tags)); - assertTrue(osmTagMapper.isWalkNoThroughTrafficExplicitlyDisallowed(tags)); + assertTrue(osmTagMapper.isBicycleThroughTrafficExplicitlyDisallowed(tags)); + assertTrue(osmTagMapper.isWalkThroughTrafficExplicitlyDisallowed(tags)); } @Test @@ -100,8 +84,8 @@ public void testFootModifier() { tags.addTag("foot", "yes"); assertTrue(osmTagMapper.isMotorVehicleThroughTrafficExplicitlyDisallowed(tags)); - assertTrue(osmTagMapper.isBicycleNoThroughTrafficExplicitlyDisallowed(tags)); - assertFalse(osmTagMapper.isWalkNoThroughTrafficExplicitlyDisallowed(tags)); + assertTrue(osmTagMapper.isBicycleThroughTrafficExplicitlyDisallowed(tags)); + assertFalse(osmTagMapper.isWalkThroughTrafficExplicitlyDisallowed(tags)); } @Test @@ -112,8 +96,8 @@ public void testVehicleDenied() { tags.addTag("vehicle", "destination"); assertTrue(osmTagMapper.isMotorVehicleThroughTrafficExplicitlyDisallowed(tags)); - assertTrue(osmTagMapper.isBicycleNoThroughTrafficExplicitlyDisallowed(tags)); - assertFalse(osmTagMapper.isWalkNoThroughTrafficExplicitlyDisallowed(tags)); + assertTrue(osmTagMapper.isBicycleThroughTrafficExplicitlyDisallowed(tags)); + assertFalse(osmTagMapper.isWalkThroughTrafficExplicitlyDisallowed(tags)); } @Test @@ -125,8 +109,8 @@ public void testVehicleDeniedMotorVehiclePermissive() { tags.addTag("motor_vehicle", "designated"); assertFalse(osmTagMapper.isMotorVehicleThroughTrafficExplicitlyDisallowed(tags)); - assertTrue(osmTagMapper.isBicycleNoThroughTrafficExplicitlyDisallowed(tags)); - assertFalse(osmTagMapper.isWalkNoThroughTrafficExplicitlyDisallowed(tags)); + assertTrue(osmTagMapper.isBicycleThroughTrafficExplicitlyDisallowed(tags)); + assertFalse(osmTagMapper.isWalkThroughTrafficExplicitlyDisallowed(tags)); } @Test @@ -138,8 +122,8 @@ public void testVehicleDeniedBicyclePermissive() { tags.addTag("bicycle", "designated"); assertTrue(osmTagMapper.isMotorVehicleThroughTrafficExplicitlyDisallowed(tags)); - assertFalse(osmTagMapper.isBicycleNoThroughTrafficExplicitlyDisallowed(tags)); - assertFalse(osmTagMapper.isWalkNoThroughTrafficExplicitlyDisallowed(tags)); + assertFalse(osmTagMapper.isBicycleThroughTrafficExplicitlyDisallowed(tags)); + assertFalse(osmTagMapper.isWalkThroughTrafficExplicitlyDisallowed(tags)); } @Test @@ -151,8 +135,8 @@ public void testMotorcycleModifier() { tags.addTag("motor_vehicle", "yes"); assertFalse(osmTagMapper.isMotorVehicleThroughTrafficExplicitlyDisallowed(tags)); - assertTrue(osmTagMapper.isBicycleNoThroughTrafficExplicitlyDisallowed(tags)); - assertTrue(osmTagMapper.isWalkNoThroughTrafficExplicitlyDisallowed(tags)); + assertTrue(osmTagMapper.isBicycleThroughTrafficExplicitlyDisallowed(tags)); + assertTrue(osmTagMapper.isWalkThroughTrafficExplicitlyDisallowed(tags)); } @Test @@ -164,8 +148,8 @@ public void testBicycleModifier() { tags.addTag("bicycle", "yes"); assertTrue(osmTagMapper.isMotorVehicleThroughTrafficExplicitlyDisallowed(tags)); - assertFalse(osmTagMapper.isBicycleNoThroughTrafficExplicitlyDisallowed(tags)); - assertTrue(osmTagMapper.isWalkNoThroughTrafficExplicitlyDisallowed(tags)); + assertFalse(osmTagMapper.isBicycleThroughTrafficExplicitlyDisallowed(tags)); + assertTrue(osmTagMapper.isWalkThroughTrafficExplicitlyDisallowed(tags)); } @Test @@ -177,8 +161,8 @@ public void testBicyclePermissive() { tags.addTag("bicycle", "permissive"); assertTrue(osmTagMapper.isMotorVehicleThroughTrafficExplicitlyDisallowed(tags)); - assertFalse(osmTagMapper.isBicycleNoThroughTrafficExplicitlyDisallowed(tags)); - assertTrue(osmTagMapper.isWalkNoThroughTrafficExplicitlyDisallowed(tags)); + assertFalse(osmTagMapper.isBicycleThroughTrafficExplicitlyDisallowed(tags)); + assertTrue(osmTagMapper.isWalkThroughTrafficExplicitlyDisallowed(tags)); } public OsmWithTags way(String key, String value) {