Search in sources :

Example 46 with IntsRef

use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.

the class FootFlagEncoderTest method testRailPlatformIssue366.

@Test
public void testRailPlatformIssue366() {
    ReaderWay way = new ReaderWay(1);
    way.setTag("railway", "platform");
    IntsRef flags = footEncoder.handleWayTags(encodingManager.createEdgeFlags(), way);
    assertFalse(flags.isEmpty());
    way.clearTags();
    way.setTag("highway", "track");
    way.setTag("railway", "platform");
    flags = footEncoder.handleWayTags(encodingManager.createEdgeFlags(), way);
    assertFalse(flags.isEmpty());
    way.clearTags();
    // only tram, no highway => no access
    way.setTag("railway", "tram");
    flags = footEncoder.handleWayTags(encodingManager.createEdgeFlags(), way);
    assertTrue(flags.isEmpty());
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 47 with IntsRef

use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.

the class MountainBikeFlagEncoderTest method testHandleWayTagsInfluencedByRelation.

@Test
public void testHandleWayTagsInfluencedByRelation() {
    ReaderWay osmWay = new ReaderWay(1);
    osmWay.setTag("highway", "track");
    ReaderRelation osmRel = new ReaderRelation(1);
    IntsRef relFlags = encodingManager.handleRelationTags(osmRel, encodingManager.createRelationFlags());
    // unchanged
    IntsRef flags = encodingManager.handleWayTags(osmWay, relFlags);
    assertEquals(18, avgSpeedEnc.getDecimal(false, flags), 1e-1);
    assertPriority(PriorityCode.PREFER.getValue(), osmWay);
    // relation code is PREFER
    osmRel.setTag("route", "bicycle");
    osmRel.setTag("network", "lcn");
    relFlags = encodingManager.handleRelationTags(osmRel, encodingManager.createRelationFlags());
    flags = encodingManager.handleWayTags(osmWay, relFlags);
    assertEquals(18, avgSpeedEnc.getDecimal(false, flags), 1e-1);
    assertPriority(PriorityCode.PREFER.getValue(), osmWay);
    // relation code is PREFER
    osmRel.setTag("network", "rcn");
    relFlags = encodingManager.handleRelationTags(osmRel, encodingManager.createRelationFlags());
    flags = encodingManager.handleWayTags(osmWay, relFlags);
    assertPriority(PriorityCode.PREFER.getValue(), osmWay);
    assertEquals(18, avgSpeedEnc.getDecimal(false, flags), 1e-1);
    // relation code is PREFER
    osmRel.setTag("network", "ncn");
    relFlags = encodingManager.handleRelationTags(osmRel, encodingManager.createRelationFlags());
    flags = encodingManager.handleWayTags(osmWay, relFlags);
    assertPriority(PriorityCode.PREFER.getValue(), osmWay);
    assertEquals(18, avgSpeedEnc.getDecimal(false, flags), 1e-1);
    // PREFER relation, but tertiary road
    // => no pushing section but road wayTypeCode and faster
    osmWay.clearTags();
    osmWay.setTag("highway", "tertiary");
    osmRel.setTag("route", "bicycle");
    osmRel.setTag("network", "lcn");
    relFlags = encodingManager.handleRelationTags(osmRel, encodingManager.createRelationFlags());
    flags = encodingManager.handleWayTags(osmWay, relFlags);
    assertEquals(18, avgSpeedEnc.getDecimal(false, flags), 1e-1);
    assertPriority(PriorityCode.PREFER.getValue(), osmWay);
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) ReaderRelation(com.graphhopper.reader.ReaderRelation) Test(org.junit.jupiter.api.Test)

Example 48 with IntsRef

use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.

the class RacingBikeFlagEncoderTest method testPriority_avoidanceOfHighMaxSpeed.

@Test
public void testPriority_avoidanceOfHighMaxSpeed() {
    // here we test the priority that would be calculated if the way was accessible (even when it is not)
    // therefore we need a modified encoder that always yields access=WAY
    BikeCommonFlagEncoder encoder = new RacingBikeFlagEncoder(new PMap("block_fords=true")) {

        @Override
        public EncodingManager.Access getAccess(ReaderWay way) {
            return WAY;
        }
    };
    EncodingManager encodingManager = EncodingManager.create(encoder);
    DecimalEncodedValue avgSpeedEnc = encoder.getAverageSpeedEnc();
    ReaderWay osmWay = new ReaderWay(1);
    osmWay.setTag("highway", "tertiary");
    osmWay.setTag("maxspeed", "50");
    IntsRef intsRef = encodingManager.createEdgeFlags();
    encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
    assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
    assertPriority(encodingManager, PREFER.getValue(), osmWay);
    osmWay.setTag("maxspeed", "60");
    encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
    assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
    assertPriority(encodingManager, PREFER.getValue(), osmWay);
    osmWay.setTag("maxspeed", "80");
    encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
    assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
    assertPriority(encodingManager, PREFER.getValue(), osmWay);
    osmWay.setTag("maxspeed", "90");
    encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
    assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
    assertPriority(encodingManager, UNCHANGED.getValue(), osmWay);
    osmWay.setTag("maxspeed", "120");
    encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
    assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
    assertPriority(encodingManager, UNCHANGED.getValue(), osmWay);
    osmWay.setTag("highway", "motorway");
    encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
    assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
    assertPriority(encodingManager, AVOID.getValue(), osmWay);
    osmWay.setTag("tunnel", "yes");
    encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
    assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
    assertPriority(encodingManager, AVOID_MORE.getValue(), osmWay);
    osmWay.clearTags();
    osmWay.setTag("highway", "motorway");
    osmWay.setTag("tunnel", "yes");
    osmWay.setTag("maxspeed", "80");
    encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
    assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
    assertPriority(encodingManager, AVOID_MORE.getValue(), osmWay);
    osmWay.clearTags();
    osmWay.setTag("highway", "motorway");
    osmWay.setTag("tunnel", "yes");
    osmWay.setTag("maxspeed", "120");
    encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
    assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
    assertPriority(encodingManager, AVOID_MORE.getValue(), osmWay);
    osmWay.clearTags();
    osmWay.setTag("highway", "notdefined");
    osmWay.setTag("tunnel", "yes");
    osmWay.setTag("maxspeed", "120");
    encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
    assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
    assertPriority(encodingManager, AVOID_MORE.getValue(), osmWay);
    osmWay.clearTags();
    osmWay.setTag("highway", "notdefined");
    osmWay.setTag("maxspeed", "50");
    encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
    assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
    assertPriority(encodingManager, UNCHANGED.getValue(), osmWay);
}
Also used : DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) PMap(com.graphhopper.util.PMap) ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 49 with IntsRef

use of com.graphhopper.storage.IntsRef 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 50 with IntsRef

use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.

the class OSMTollParserTest method testSimpleTags.

@Test
public void testSimpleTags() {
    ReaderWay readerWay = new ReaderWay(1);
    IntsRef relFlags = em.createRelationFlags();
    IntsRef intsRef = em.createEdgeFlags();
    readerWay.setTag("highway", "primary");
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(Toll.MISSING, tollEnc.getEnum(false, intsRef));
    intsRef = em.createEdgeFlags();
    readerWay.setTag("highway", "primary");
    readerWay.setTag("toll:hgv", "yes");
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(Toll.HGV, tollEnc.getEnum(false, intsRef));
    intsRef = em.createEdgeFlags();
    readerWay.setTag("highway", "primary");
    readerWay.setTag("toll:N2", "yes");
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(Toll.HGV, tollEnc.getEnum(false, intsRef));
    intsRef = em.createEdgeFlags();
    readerWay.setTag("highway", "primary");
    readerWay.setTag("toll:N3", "yes");
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(Toll.HGV, tollEnc.getEnum(false, intsRef));
    intsRef = em.createEdgeFlags();
    readerWay.setTag("highway", "primary");
    readerWay.setTag("toll", "yes");
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(Toll.ALL, tollEnc.getEnum(false, intsRef));
    intsRef = em.createEdgeFlags();
    readerWay.setTag("highway", "primary");
    readerWay.setTag("toll", "yes");
    readerWay.setTag("toll:hgv", "yes");
    readerWay.setTag("toll:N2", "yes");
    readerWay.setTag("toll:N3", "yes");
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(Toll.ALL, tollEnc.getEnum(false, intsRef));
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Aggregations

IntsRef (com.graphhopper.storage.IntsRef)108 Test (org.junit.jupiter.api.Test)96 ReaderWay (com.graphhopper.reader.ReaderWay)67 ReaderRelation (com.graphhopper.reader.ReaderRelation)7 GraphBuilder (com.graphhopper.storage.GraphBuilder)7 EncodingManager (com.graphhopper.routing.util.EncodingManager)5 Graph (com.graphhopper.storage.Graph)5 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)4 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)4 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)3 NodeAccess (com.graphhopper.storage.NodeAccess)3 BooleanEncodedValue (com.graphhopper.routing.ev.BooleanEncodedValue)2 RoadEnvironment (com.graphhopper.routing.ev.RoadEnvironment)2 VirtualEdgeIteratorState (com.graphhopper.routing.querygraph.VirtualEdgeIteratorState)2 TransportationMode (com.graphhopper.routing.util.TransportationMode)2 CountryRule (com.graphhopper.routing.util.countryrules.CountryRule)2 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)2 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)2 PMap (com.graphhopper.util.PMap)2 PointList (com.graphhopper.util.PointList)2