use of com.graphhopper.routing.util.TransportationMode in project graphhopper by graphhopper.
the class OSMRoadAccessParserTest method countryRule.
@Test
void countryRule() {
EncodingManager em = EncodingManager.create("car");
EnumEncodedValue<RoadAccess> roadAccessEnc = em.getEnumEncodedValue(RoadAccess.KEY, RoadAccess.class);
Graph graph = new GraphBuilder(em).create();
FlagEncoder encoder = em.getEncoder("car");
EdgeIteratorState e1 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(100));
EdgeIteratorState e2 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(100));
OSMRoadAccessParser parser = new OSMRoadAccessParser(roadAccessEnc, OSMRoadAccessParser.toOSMRestrictions(TransportationMode.CAR));
IntsRef relFlags = em.createRelationFlags();
ReaderWay way = new ReaderWay(27L);
way.setTag("highway", "track");
way.setTag("country_rule", new CountryRule() {
@Override
public RoadAccess getAccess(ReaderWay readerWay, TransportationMode transportationMode, RoadAccess currentRoadAccess) {
return RoadAccess.DESTINATION;
}
});
parser.handleWayTags(e1.getFlags(), way, relFlags);
assertEquals(RoadAccess.DESTINATION, e1.get(roadAccessEnc));
// if there is no country rule we get the default value
way.removeTag("country_rule");
parser.handleWayTags(e2.getFlags(), way, relFlags);
assertEquals(RoadAccess.YES, e2.get(roadAccessEnc));
}
use of com.graphhopper.routing.util.TransportationMode in project graphhopper by graphhopper.
the class OSMMaxSpeedParserTest method countryRule.
@Test
void countryRule() {
EncodingManager em = EncodingManager.create("car");
DecimalEncodedValue maxSpeedEnc = em.getDecimalEncodedValue(MaxSpeed.KEY);
Graph graph = new GraphBuilder(em).create();
FlagEncoder encoder = em.getEncoder("car");
EdgeIteratorState e1 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(100));
EdgeIteratorState e2 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(100));
OSMMaxSpeedParser parser = new OSMMaxSpeedParser(maxSpeedEnc);
IntsRef relFlags = em.createRelationFlags();
ReaderWay way = new ReaderWay(29L);
way.setTag("highway", "living_street");
way.setTag("country_rule", new CountryRule() {
@Override
public double getMaxSpeed(ReaderWay readerWay, TransportationMode transportationMode, double currentMaxSpeed) {
return 5;
}
});
parser.handleWayTags(e1.getFlags(), way, relFlags);
assertEquals(5, e1.get(maxSpeedEnc), .1);
// without a country_rule we get the default value
way.removeTag("country_rule");
parser.handleWayTags(e2.getFlags(), way, relFlags);
assertEquals(MaxSpeed.UNSET_SPEED, e2.get(maxSpeedEnc), .1);
}
Aggregations