Search in sources :

Example 76 with ReaderWay

use of com.graphhopper.reader.ReaderWay 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 77 with ReaderWay

use of com.graphhopper.reader.ReaderWay in project graphhopper by graphhopper.

the class OSMRoadClassParserTest method testSimpleTags.

@Test
public void testSimpleTags() {
    ReaderWay readerWay = new ReaderWay(1);
    IntsRef edgeFlags = em.createEdgeFlags();
    readerWay.setTag("highway", "primary");
    parser.handleWayTags(edgeFlags, readerWay, relFlags);
    assertEquals(RoadClass.PRIMARY, rcEnc.getEnum(false, edgeFlags));
    edgeFlags = em.createEdgeFlags();
    readerWay.setTag("highway", "unknownstuff");
    parser.handleWayTags(edgeFlags, readerWay, relFlags);
    assertEquals(RoadClass.OTHER, rcEnc.getEnum(false, edgeFlags));
    edgeFlags = em.createEdgeFlags();
    readerWay.setTag("highway", "motorway_link");
    parser.handleWayTags(edgeFlags, readerWay, relFlags);
    assertEquals(RoadClass.MOTORWAY, rcEnc.getEnum(false, edgeFlags));
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 78 with ReaderWay

use of com.graphhopper.reader.ReaderWay in project graphhopper by graphhopper.

the class CountryRuleTest method createReaderWay.

private ReaderWay createReaderWay(String highway) {
    ReaderWay readerWay = new ReaderWay(123L);
    readerWay.setTag("highway", highway);
    return readerWay;
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay)

Example 79 with ReaderWay

use of com.graphhopper.reader.ReaderWay in project graphhopper by graphhopper.

the class OSMHazmatParserTest method testNoNPE.

@Test
public void testNoNPE() {
    ReaderWay readerWay = new ReaderWay(1);
    IntsRef intsRef = em.createEdgeFlags();
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(Hazmat.YES, hazEnc.getEnum(false, intsRef));
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 80 with ReaderWay

use of com.graphhopper.reader.ReaderWay in project graphhopper by graphhopper.

the class OSMHazmatWaterParserTest method testSimpleTags.

@Test
public void testSimpleTags() {
    ReaderWay readerWay = new ReaderWay(1);
    IntsRef intsRef = em.createEdgeFlags();
    readerWay.setTag("hazmat:water", "no");
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(HazmatWater.NO, hazWaterEnc.getEnum(false, intsRef));
    intsRef = em.createEdgeFlags();
    readerWay.setTag("hazmat:water", "yes");
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(HazmatWater.YES, hazWaterEnc.getEnum(false, intsRef));
    intsRef = em.createEdgeFlags();
    readerWay.setTag("hazmat:water", "permissive");
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(HazmatWater.PERMISSIVE, hazWaterEnc.getEnum(false, intsRef));
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Aggregations

ReaderWay (com.graphhopper.reader.ReaderWay)157 Test (org.junit.jupiter.api.Test)119 IntsRef (com.graphhopper.storage.IntsRef)67 Test (org.junit.Test)24 EncodingManager (com.graphhopper.routing.util.EncodingManager)9 GraphBuilder (com.graphhopper.storage.GraphBuilder)9 ReaderRelation (com.graphhopper.reader.ReaderRelation)8 ConditionalTagInspector (com.graphhopper.reader.ConditionalTagInspector)7 Graph (com.graphhopper.storage.Graph)7 DateFormat (java.text.DateFormat)6 Date (java.util.Date)6 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)5 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)5 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)4 PMap (com.graphhopper.util.PMap)4 BooleanEncodedValue (com.graphhopper.routing.ev.BooleanEncodedValue)3 DataFlagEncoder (com.graphhopper.routing.util.DataFlagEncoder)3 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)3 GHPoint (com.graphhopper.util.shapes.GHPoint)3 LongIndexedContainer (com.carrotsearch.hppc.LongIndexedContainer)2