Search in sources :

Example 1 with CountryRule

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));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) RoadAccess(com.graphhopper.routing.ev.RoadAccess) TransportationMode(com.graphhopper.routing.util.TransportationMode) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) ReaderWay(com.graphhopper.reader.ReaderWay) Graph(com.graphhopper.storage.Graph) CountryRule(com.graphhopper.routing.util.countryrules.CountryRule) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) GraphBuilder(com.graphhopper.storage.GraphBuilder) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 2 with CountryRule

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);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) TransportationMode(com.graphhopper.routing.util.TransportationMode) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) ReaderWay(com.graphhopper.reader.ReaderWay) Graph(com.graphhopper.storage.Graph) CountryRule(com.graphhopper.routing.util.countryrules.CountryRule) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) GraphBuilder(com.graphhopper.storage.GraphBuilder) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 3 with CountryRule

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;
}
Also used : CountryRule(com.graphhopper.routing.util.countryrules.CountryRule)

Example 4 with CountryRule

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;
}
Also used : RoadAccess(com.graphhopper.routing.ev.RoadAccess) CountryRule(com.graphhopper.routing.util.countryrules.CountryRule)

Example 5 with CountryRule

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;
}
Also used : CountryRule(com.graphhopper.routing.util.countryrules.CountryRule)

Aggregations

CountryRule (com.graphhopper.routing.util.countryrules.CountryRule)7 ReaderWay (com.graphhopper.reader.ReaderWay)2 RoadAccess (com.graphhopper.routing.ev.RoadAccess)2 EncodingManager (com.graphhopper.routing.util.EncodingManager)2 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)2 TransportationMode (com.graphhopper.routing.util.TransportationMode)2 Graph (com.graphhopper.storage.Graph)2 GraphBuilder (com.graphhopper.storage.GraphBuilder)2 IntsRef (com.graphhopper.storage.IntsRef)2 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)2 Test (org.junit.jupiter.api.Test)2 Country (com.graphhopper.routing.ev.Country)1 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)1 Toll (com.graphhopper.routing.ev.Toll)1 CustomArea (com.graphhopper.routing.util.CustomArea)1 IOException (java.io.IOException)1