use of com.graphhopper.routing.util.countryrules.CountryRule 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.countryrules.CountryRule 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);
}
use of com.graphhopper.routing.util.countryrules.CountryRule in project graphhopper by graphhopper.
the class OSMMaxSpeedParser method handleWayTags.
@Override
public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay way, IntsRef relationFlags) {
double maxSpeed = OSMValueExtractor.stringToKmh(way.getTag("maxspeed"));
CountryRule countryRule = way.getTag("country_rule", null);
if (countryRule != null)
maxSpeed = countryRule.getMaxSpeed(way, TransportationMode.CAR, maxSpeed);
double fwdSpeed = OSMValueExtractor.stringToKmh(way.getTag("maxspeed:forward"));
if (!isValidSpeed(fwdSpeed) && isValidSpeed(maxSpeed))
fwdSpeed = maxSpeed;
double maxPossibleSpeed = MaxSpeed.UNLIMITED_SIGN_SPEED;
if (isValidSpeed(fwdSpeed) && fwdSpeed > maxPossibleSpeed)
fwdSpeed = maxPossibleSpeed;
double bwdSpeed = OSMValueExtractor.stringToKmh(way.getTag("maxspeed:backward"));
if (!isValidSpeed(bwdSpeed) && isValidSpeed(maxSpeed))
bwdSpeed = maxSpeed;
if (isValidSpeed(bwdSpeed) && bwdSpeed > maxPossibleSpeed)
bwdSpeed = maxPossibleSpeed;
if (!isValidSpeed(fwdSpeed))
fwdSpeed = UNSET_SPEED;
carMaxSpeedEnc.setDecimal(false, edgeFlags, fwdSpeed);
if (!isValidSpeed(bwdSpeed))
bwdSpeed = UNSET_SPEED;
carMaxSpeedEnc.setDecimal(true, edgeFlags, bwdSpeed);
return edgeFlags;
}
use of com.graphhopper.routing.util.countryrules.CountryRule in project graphhopper by graphhopper.
the class OSMRoadAccessParser method handleWayTags.
@Override
public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay readerWay, IntsRef relationFlags) {
RoadAccess accessValue = YES;
RoadAccess tmpAccessValue;
for (String restriction : restrictions) {
tmpAccessValue = RoadAccess.find(readerWay.getTag(restriction, "yes"));
if (tmpAccessValue != null && tmpAccessValue.ordinal() > accessValue.ordinal()) {
accessValue = tmpAccessValue;
}
}
CountryRule countryRule = readerWay.getTag("country_rule", null);
if (countryRule != null)
accessValue = countryRule.getAccess(readerWay, TransportationMode.CAR, accessValue);
roadAccessEnc.setEnum(false, edgeFlags, accessValue);
return edgeFlags;
}
use of com.graphhopper.routing.util.countryrules.CountryRule in project graphhopper by graphhopper.
the class OSMAccessParser method handleWayTags.
@Override
public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay way, IntsRef relationFlags) {
RoadAccess accessValue = YES;
RoadAccess tmpAccessValue;
for (String restriction : restrictions) {
tmpAccessValue = RoadAccess.find(way.getTag(restriction, "yes"));
if (tmpAccessValue != null && tmpAccessValue.ordinal() > accessValue.ordinal()) {
accessValue = tmpAccessValue;
}
}
CountryRule countryRule = way.getTag("country_rule", null);
if (countryRule != null)
accessValue = countryRule.getAccess(way, transportationMode, accessValue);
boolean access = accessValue != RoadAccess.NO;
accessEnc.setBool(false, edgeFlags, access);
if (access) {
boolean isRoundabout = roundaboutEnc.getBool(false, edgeFlags);
if (transportationMode.isMotorVehicle() && (isOneway(way) || isRoundabout)) {
if (isForwardOneway(way))
accessEnc.setBool(false, edgeFlags, true);
if (isBackwardOneway(way))
accessEnc.setBool(true, edgeFlags, true);
} else if (transportationMode == TransportationMode.BIKE && (isBikeOneway(way) || isRoundabout && !way.hasTag("oneway:bicycle", "no") && !way.hasTag("cycleway", oppositeLanes) && !way.hasTag("cycleway:left", oppositeLanes) && !way.hasTag("cycleway:right", oppositeLanes) && !way.hasTag("cycleway:left:oneway", "-1") && !way.hasTag("cycleway:right:oneway", "-1"))) {
boolean isBackward = way.hasTag("oneway", "-1") || way.hasTag("oneway:bicycle", "-1") || way.hasTag("vehicle:forward", restrictedValues) || way.hasTag("bicycle:forward", restrictedValues);
accessEnc.setBool(isBackward, edgeFlags, true);
} else {
accessEnc.setBool(false, edgeFlags, true);
accessEnc.setBool(true, edgeFlags, true);
}
}
return edgeFlags;
}
Aggregations