use of org.opentripplanner.openstreetmap.model.OSMWithTags in project OpenTripPlanner by opentripplanner.
the class TestOpenStreetMapGraphBuilder method testWayDataSet.
@Test
public void testWayDataSet() {
OSMWithTags way = new OSMWay();
way.addTag("highway", "footway");
way.addTag("cycleway", "lane");
way.addTag("access", "no");
way.addTag("surface", "gravel");
WayPropertySet wayPropertySet = new WayPropertySet();
// where there are no way specifiers, the default is used
assertEquals(wayPropertySet.getDataForWay(way), wayPropertySet.defaultProperties);
// add two equal matches: lane only...
OSMSpecifier lane_only = new OSMSpecifier();
lane_only.addTag("cycleway", "lane");
WayProperties lane_is_safer = new WayProperties();
lane_is_safer.setSafetyFeatures(new P2<Double>(1.5, 1.5));
wayPropertySet.addProperties(lane_only, lane_is_safer);
// and footway only
OSMSpecifier footway_only = new OSMSpecifier();
footway_only.addTag("highway", "footway");
WayProperties footways_allow_peds = new WayProperties();
footways_allow_peds.setPermission(StreetTraversalPermission.PEDESTRIAN);
wayPropertySet.addProperties(footway_only, footways_allow_peds);
WayProperties dataForWay = wayPropertySet.getDataForWay(way);
// the first one is found
assertEquals(dataForWay, lane_is_safer);
// add a better match
OSMSpecifier lane_and_footway = new OSMSpecifier();
lane_and_footway.addTag("cycleway", "lane");
lane_and_footway.addTag("highway", "footway");
WayProperties safer_and_peds = new WayProperties();
safer_and_peds.setSafetyFeatures(new P2<Double>(0.75, 0.75));
safer_and_peds.setPermission(StreetTraversalPermission.PEDESTRIAN);
wayPropertySet.addProperties(lane_and_footway, safer_and_peds);
dataForWay = wayPropertySet.getDataForWay(way);
assertEquals(dataForWay, safer_and_peds);
// add a mixin
OSMSpecifier gravel = new OSMSpecifier("surface=gravel");
WayProperties gravel_is_dangerous = new WayProperties();
gravel_is_dangerous.setSafetyFeatures(new P2<Double>(2.0, 2.0));
wayPropertySet.addProperties(gravel, gravel_is_dangerous, true);
dataForWay = wayPropertySet.getDataForWay(way);
assertEquals(dataForWay.getSafetyFeatures().first, 1.5);
// test a left-right distinction
way = new OSMWay();
way.addTag("highway", "footway");
way.addTag("cycleway", "lane");
way.addTag("cycleway:right", "track");
OSMSpecifier track_only = new OSMSpecifier("highway=footway;cycleway=track");
WayProperties track_is_safest = new WayProperties();
track_is_safest.setSafetyFeatures(new P2<Double>(0.25, 0.25));
wayPropertySet.addProperties(track_only, track_is_safest);
dataForWay = wayPropertySet.getDataForWay(way);
// right (with traffic) comes
assertEquals(0.25, dataForWay.getSafetyFeatures().first);
// from track
// left comes from lane
assertEquals(0.75, dataForWay.getSafetyFeatures().second);
way = new OSMWay();
way.addTag("highway", "footway");
way.addTag("footway", "sidewalk");
way.addTag("RLIS:reviewed", "no");
WayPropertySet propset = new WayPropertySet();
CreativeNamer namer = new CreativeNamer("platform");
propset.addCreativeNamer(new OSMSpecifier("railway=platform;highway=footway;footway=sidewalk"), namer);
namer = new CreativeNamer("sidewalk");
propset.addCreativeNamer(new OSMSpecifier("highway=footway;footway=sidewalk"), namer);
assertEquals("sidewalk", propset.getCreativeNameForWay(way).toString());
}
use of org.opentripplanner.openstreetmap.model.OSMWithTags in project OpenTripPlanner by opentripplanner.
the class TestWayPropertySet method testCarSpeeds.
/**
* Test that car speeds are calculated accurately
*/
@Test
public void testCarSpeeds() {
WayPropertySet wps = new WayPropertySet();
DefaultWayPropertySetSource source = new DefaultWayPropertySetSource();
source.populateProperties(wps);
OSMWithTags way;
float epsilon = 0.01f;
way = new OSMWithTags();
way.addTag("maxspeed", "60");
assertTrue(within(kmhAsMs(60), wps.getCarSpeedForWay(way, false), epsilon));
assertTrue(within(kmhAsMs(60), wps.getCarSpeedForWay(way, true), epsilon));
way = new OSMWithTags();
way.addTag("maxspeed:forward", "80");
way.addTag("maxspeed:reverse", "20");
way.addTag("maxspeed", "40");
assertTrue(within(kmhAsMs(80), wps.getCarSpeedForWay(way, false), epsilon));
assertTrue(within(kmhAsMs(20), wps.getCarSpeedForWay(way, true), epsilon));
way = new OSMWithTags();
way.addTag("maxspeed", "40");
way.addTag("maxspeed:lanes", "60|80|40");
assertTrue(within(kmhAsMs(80), wps.getCarSpeedForWay(way, false), epsilon));
assertTrue(within(kmhAsMs(80), wps.getCarSpeedForWay(way, true), epsilon));
way = new OSMWithTags();
way.addTag("maxspeed", "20");
way.addTag("maxspeed:motorcar", "80");
assertTrue(within(kmhAsMs(80), wps.getCarSpeedForWay(way, false), epsilon));
assertTrue(within(kmhAsMs(80), wps.getCarSpeedForWay(way, true), epsilon));
// test with english units
way = new OSMWithTags();
way.addTag("maxspeed", "35 mph");
assertTrue(within(kmhAsMs(35 * 1.609f), wps.getCarSpeedForWay(way, false), epsilon));
assertTrue(within(kmhAsMs(35 * 1.609f), wps.getCarSpeedForWay(way, true), epsilon));
// test with no maxspeed tags
wps = new WayPropertySet();
wps.addSpeedPicker(getSpeedPicker("highway=motorway", kmhAsMs(100)));
wps.addSpeedPicker(getSpeedPicker("highway=*", kmhAsMs(35)));
wps.addSpeedPicker(getSpeedPicker("surface=gravel", kmhAsMs(10)));
wps.defaultSpeed = kmhAsMs(25);
way = new OSMWithTags();
// test default speeds
assertTrue(within(kmhAsMs(25), wps.getCarSpeedForWay(way, false), epsilon));
assertTrue(within(kmhAsMs(25), wps.getCarSpeedForWay(way, true), epsilon));
way.addTag("highway", "tertiary");
assertTrue(within(kmhAsMs(35), wps.getCarSpeedForWay(way, false), epsilon));
assertTrue(within(kmhAsMs(35), wps.getCarSpeedForWay(way, true), epsilon));
way = new OSMWithTags();
way.addTag("surface", "gravel");
assertTrue(within(kmhAsMs(10), wps.getCarSpeedForWay(way, false), epsilon));
assertTrue(within(kmhAsMs(10), wps.getCarSpeedForWay(way, true), epsilon));
way = new OSMWithTags();
way.addTag("highway", "motorway");
assertTrue(within(kmhAsMs(100), wps.getCarSpeedForWay(way, false), epsilon));
assertTrue(within(kmhAsMs(100), wps.getCarSpeedForWay(way, true), epsilon));
// make sure that 0-speed ways can't exist
way = new OSMWithTags();
way.addTag("maxspeed", "0");
assertTrue(within(kmhAsMs(25), wps.getCarSpeedForWay(way, false), epsilon));
assertTrue(within(kmhAsMs(25), wps.getCarSpeedForWay(way, true), epsilon));
}
Aggregations