Skip to content

Commit

Permalink
Merge pull request #6288 from leonardehrenfried/motorroad
Browse files Browse the repository at this point in the history
Make `motorroad=yes` car-only
  • Loading branch information
leonardehrenfried authored Dec 3, 2024
2 parents c7fe2f2 + 2aefc16 commit 54f69b0
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ else if (speedLimit <= 16.65f) {
// Don't recommend walking in trunk road tunnels
props.setProperties("highway=trunk;tunnel=yes", withModes(CAR).bicycleSafety(7.47));

// Do not walk on "moottoriliikennetie"
props.setProperties("motorroad=yes", withModes(CAR).bicycleSafety(7.47));

// Remove informal and private roads
props.setProperties("highway=*;informal=yes", withModes(NONE));
props.setProperties("highway=service;access=private", withModes(NONE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.opentripplanner.osm.wayproperty.WayProperties;
import org.opentripplanner.osm.wayproperty.WayPropertySet;
import org.opentripplanner.osm.wayproperty.specifier.BestMatchSpecifier;
import org.opentripplanner.osm.wayproperty.specifier.Condition;
import org.opentripplanner.osm.wayproperty.specifier.ExactMatchSpecifier;
import org.opentripplanner.osm.wayproperty.specifier.LogicalOrSpecifier;
import org.opentripplanner.routing.services.notes.StreetNotesService;
Expand Down Expand Up @@ -104,6 +103,10 @@ public void populateProperties(WayPropertySet props) {
props.setProperties("highway=trunk", withModes(CAR).bicycleSafety(7.47));
props.setProperties("highway=motorway", withModes(CAR).bicycleSafety(8));

// Do not walk on "moottoriliikennetie"/"Kraftfahrstrasse"/"Limited access road"
// https://en.wikipedia.org/wiki/Limited-access_road
props.setProperties(new ExactMatchSpecifier("motorroad=yes"), withModes(CAR));

/* cycleway=lane */
props.setProperties(
"highway=*;cycleway=lane",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opentripplanner.street.model.StreetTraversalPermission.ALL;
import static org.opentripplanner.street.model.StreetTraversalPermission.CAR;
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;
Expand All @@ -12,15 +14,16 @@
import org.opentripplanner.osm.model.OsmWithTags;
import org.opentripplanner.osm.wayproperty.WayProperties;
import org.opentripplanner.osm.wayproperty.WayPropertySet;
import org.opentripplanner.osm.wayproperty.specifier.WayTestData;

public class FinlandMapperTest {
class FinlandMapperTest {

private WayPropertySet wps;
private OsmTagMapper mapper;
static float epsilon = 0.01f;

@BeforeEach
public void setup() {
void setup() {
this.wps = new WayPropertySet();
this.mapper = new FinlandMapper();
this.mapper.populateProperties(this.wps);
Expand All @@ -30,7 +33,7 @@ public void setup() {
* Test that bike and walk safety factors are calculated accurately
*/
@Test
public void testSafety() {
void testSafety() {
OsmWithTags primaryWay = new OsmWithTags();
primaryWay.addTag("highway", "primary");
primaryWay.addTag("oneway", "no");
Expand Down Expand Up @@ -141,7 +144,7 @@ public void testSafety() {
}

@Test
public void testSafetyWithMixins() {
void testSafetyWithMixins() {
OsmWithTags wayWithMixins = new OsmWithTags();
// highway=service has no custom bicycle or walk safety
wayWithMixins.addTag("highway", "unclassified");
Expand Down Expand Up @@ -179,7 +182,7 @@ public void testSafetyWithMixins() {
}

@Test
public void testTagMapping() {
void testTagMapping() {
OsmWithTags way;
WayProperties wayData;

Expand All @@ -206,7 +209,7 @@ public void testTagMapping() {
* Test that biking is not allowed in footway areas and transit platforms
*/
@Test
public void testArea() {
void testArea() {
OsmWithTags way;
WayProperties wayData;

Expand All @@ -227,10 +230,21 @@ public void testArea() {
}

@Test
public void serviceNoThroughTraffic() {
void serviceNoThroughTraffic() {
var way = new OsmWay();
way.addTag("highway", "residential");
way.addTag("service", "driveway");
assertTrue(mapper.isMotorVehicleThroughTrafficExplicitlyDisallowed(way));
}

@Test
void motorroad() {
OsmTagMapper osmTagMapper = new FinlandMapper();
WayPropertySet wps = new WayPropertySet();
osmTagMapper.populateProperties(wps);
var way = WayTestData.carTunnel();
assertEquals(ALL, wps.getDataForWay(way).getPermission());
way.addTag("motorroad", "yes");
assertEquals(CAR, wps.getDataForWay(way).getPermission());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opentripplanner.street.model.StreetTraversalPermission.ALL;
import static org.opentripplanner.street.model.StreetTraversalPermission.CAR;

import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.opentripplanner.osm.model.OsmWithTags;
import org.opentripplanner.osm.wayproperty.WayPropertySet;
import org.opentripplanner.osm.wayproperty.specifier.WayTestData;

public class OsmTagMapperTest {
class OsmTagMapperTest {

@Test
public void isMotorThroughTrafficExplicitlyDisallowed() {
void isMotorThroughTrafficExplicitlyDisallowed() {
OsmWithTags o = new OsmWithTags();
OsmTagMapper osmTagMapper = new OsmTagMapper();

Expand All @@ -34,7 +40,7 @@ public void isMotorThroughTrafficExplicitlyDisallowed() {
}

@Test
public void isBicycleThroughTrafficExplicitlyDisallowed() {
void isBicycleThroughTrafficExplicitlyDisallowed() {
OsmTagMapper osmTagMapper = new OsmTagMapper();
assertTrue(
osmTagMapper.isBicycleThroughTrafficExplicitlyDisallowed(way("bicycle", "destination"))
Expand All @@ -45,14 +51,14 @@ public void isBicycleThroughTrafficExplicitlyDisallowed() {
}

@Test
public void isWalkThroughTrafficExplicitlyDisallowed() {
void isWalkThroughTrafficExplicitlyDisallowed() {
OsmTagMapper osmTagMapper = new OsmTagMapper();
assertTrue(osmTagMapper.isWalkThroughTrafficExplicitlyDisallowed(way("foot", "destination")));
assertTrue(osmTagMapper.isWalkThroughTrafficExplicitlyDisallowed(way("access", "destination")));
}

@Test
public void testAccessNo() {
void testAccessNo() {
OsmWithTags tags = new OsmWithTags();
OsmTagMapper osmTagMapper = new OsmTagMapper();

Expand All @@ -64,7 +70,7 @@ public void testAccessNo() {
}

@Test
public void testAccessPrivate() {
void testAccessPrivate() {
OsmWithTags tags = new OsmWithTags();
OsmTagMapper osmTagMapper = new OsmTagMapper();

Expand All @@ -76,7 +82,7 @@ public void testAccessPrivate() {
}

@Test
public void testFootModifier() {
void testFootModifier() {
OsmWithTags tags = new OsmWithTags();
OsmTagMapper osmTagMapper = new OsmTagMapper();

Expand All @@ -89,7 +95,7 @@ public void testFootModifier() {
}

@Test
public void testVehicleDenied() {
void testVehicleDenied() {
OsmWithTags tags = new OsmWithTags();
OsmTagMapper osmTagMapper = new OsmTagMapper();

Expand All @@ -101,7 +107,7 @@ public void testVehicleDenied() {
}

@Test
public void testVehicleDeniedMotorVehiclePermissive() {
void testVehicleDeniedMotorVehiclePermissive() {
OsmWithTags tags = new OsmWithTags();
OsmTagMapper osmTagMapper = new OsmTagMapper();

Expand All @@ -114,7 +120,7 @@ public void testVehicleDeniedMotorVehiclePermissive() {
}

@Test
public void testVehicleDeniedBicyclePermissive() {
void testVehicleDeniedBicyclePermissive() {
OsmWithTags tags = new OsmWithTags();
OsmTagMapper osmTagMapper = new OsmTagMapper();

Expand All @@ -127,7 +133,7 @@ public void testVehicleDeniedBicyclePermissive() {
}

@Test
public void testMotorcycleModifier() {
void testMotorcycleModifier() {
OsmWithTags tags = new OsmWithTags();
OsmTagMapper osmTagMapper = new OsmTagMapper();

Expand All @@ -140,7 +146,7 @@ public void testMotorcycleModifier() {
}

@Test
public void testBicycleModifier() {
void testBicycleModifier() {
OsmWithTags tags = new OsmWithTags();
OsmTagMapper osmTagMapper = new OsmTagMapper();

Expand All @@ -153,7 +159,7 @@ public void testBicycleModifier() {
}

@Test
public void testBicyclePermissive() {
void testBicyclePermissive() {
OsmWithTags tags = new OsmWithTags();
OsmTagMapper osmTagMapper = new OsmTagMapper();

Expand All @@ -165,6 +171,29 @@ public void testBicyclePermissive() {
assertTrue(osmTagMapper.isWalkThroughTrafficExplicitlyDisallowed(tags));
}

public static List<OsmWithTags> roadCases() {
return List.of(
WayTestData.carTunnel(),
WayTestData.southwestMayoStreet(),
WayTestData.southeastLaBonitaWay(),
WayTestData.fiveLanes(),
WayTestData.highwayTertiary()
);
}

@ParameterizedTest
@MethodSource("roadCases")
void motorroad(OsmWithTags way) {
OsmTagMapper osmTagMapper = new OsmTagMapper();
WayPropertySet wps = new WayPropertySet();
osmTagMapper.populateProperties(wps);

assertEquals(ALL, wps.getDataForWay(way).getPermission());

way.addTag("motorroad", "yes");
assertEquals(CAR, wps.getDataForWay(way).getPermission());
}

public OsmWithTags way(String key, String value) {
var way = new OsmWithTags();
way.addTag(key, value);
Expand Down
2 changes: 1 addition & 1 deletion doc/user/osm/Finland.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Lower safety values make an OSM way more desirable and higher values less desira
| `highway=trunk_link` | `ALL` | 2.06 | |
| `highway=trunk` | `ALL` | 7.47 | |
| `highway=trunk; tunnel=yes` | `CAR` | 7.47 | |
| `motorroad=yes` | `CAR` | 7.47 | |
| `present(highway); informal=yes` | `NONE` | | |
| `highway=service; access=private` | `NONE` | | |
| `highway=trail` | `NONE` | | |
Expand Down Expand Up @@ -105,6 +104,7 @@ Lower safety values make an OSM way more desirable and higher values less desira
| `highway=motorway_link` | `CAR` | 2.06 | |
| `highway=trunk` | `CAR` | 7.47 | |
| `highway=motorway` | `CAR` | 8.0 | |
| `motorroad=yes` | `CAR` | | |
| `present(highway); cycleway=lane` | `PEDESTRIAN_AND_BICYCLE` | 0.87 | |
| `highway=service; cycleway=lane` | `ALL` | 0.77 | |
| `highway=residential; cycleway=lane` | `ALL` | 0.77 | |
Expand Down
1 change: 1 addition & 0 deletions doc/user/osm/Germany.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Lower safety values make an OSM way more desirable and higher values less desira
| `highway=motorway_link` | `CAR` | 2.06 | |
| `highway=trunk` | `CAR` | 7.47 | |
| `highway=motorway` | `CAR` | 8.0 | |
| `motorroad=yes` | `CAR` | | |
| `present(highway); cycleway=lane` | `PEDESTRIAN_AND_BICYCLE` | 0.87 | |
| `highway=service; cycleway=lane` | `ALL` | 0.77 | |
| `highway=residential; cycleway=lane` | `ALL` | 0.77 | |
Expand Down
1 change: 1 addition & 0 deletions doc/user/osm/OsmTag.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Lower safety values make an OSM way more desirable and higher values less desira
| `highway=motorway_link` | `CAR` | 2.06 | |
| `highway=trunk` | `CAR` | 7.47 | |
| `highway=motorway` | `CAR` | 8.0 | |
| `motorroad=yes` | `CAR` | | |
| `present(highway); cycleway=lane` | `PEDESTRIAN_AND_BICYCLE` | 0.87 | |
| `highway=service; cycleway=lane` | `ALL` | 0.77 | |
| `highway=residential; cycleway=lane` | `ALL` | 0.77 | |
Expand Down
1 change: 1 addition & 0 deletions doc/user/osm/UK.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Lower safety values make an OSM way more desirable and higher values less desira
| `highway=motorway_link` | `CAR` | 2.06 | |
| `highway=trunk` | `CAR` | 7.47 | |
| `highway=motorway` | `CAR` | 8.0 | |
| `motorroad=yes` | `CAR` | | |
| `present(highway); cycleway=lane` | `PEDESTRIAN_AND_BICYCLE` | 0.87 | |
| `highway=service; cycleway=lane` | `ALL` | 0.77 | |
| `highway=residential; cycleway=lane` | `ALL` | 0.77 | |
Expand Down

0 comments on commit 54f69b0

Please sign in to comment.