Search in sources :

Example 71 with ReaderWay

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

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

Example 73 with ReaderWay

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

the class OSMHazmatTunnelParserTest method testIgnoreNonTunnelSubtags.

@Test
public void testIgnoreNonTunnelSubtags() {
    IntsRef intsRef = em.createEdgeFlags();
    ReaderWay readerWay = new ReaderWay(1);
    readerWay.setTag("hazmat:B", "no");
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(HazmatTunnel.A, hazTunnelEnc.getEnum(false, intsRef));
}
Also used : IntsRef(com.graphhopper.storage.IntsRef) ReaderWay(com.graphhopper.reader.ReaderWay) Test(org.junit.jupiter.api.Test)

Example 74 with ReaderWay

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

the class OSMHazmatTunnelParserTest method testTunnelCat.

@Test
public void testTunnelCat() {
    IntsRef intsRef = em.createEdgeFlags();
    ReaderWay readerWay = new ReaderWay(1);
    readerWay.setTag("hazmat:tunnel_cat", "A");
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(HazmatTunnel.A, hazTunnelEnc.getEnum(false, intsRef));
    intsRef = em.createEdgeFlags();
    readerWay = new ReaderWay(1);
    readerWay.setTag("hazmat:tunnel_cat", "B");
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(HazmatTunnel.B, hazTunnelEnc.getEnum(false, intsRef));
    intsRef = em.createEdgeFlags();
    readerWay = new ReaderWay(1);
    readerWay.setTag("hazmat:tunnel_cat", "C");
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(HazmatTunnel.C, hazTunnelEnc.getEnum(false, intsRef));
    intsRef = em.createEdgeFlags();
    readerWay = new ReaderWay(1);
    readerWay.setTag("hazmat:tunnel_cat", "D");
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(HazmatTunnel.D, hazTunnelEnc.getEnum(false, intsRef));
    intsRef = em.createEdgeFlags();
    readerWay = new ReaderWay(1);
    readerWay.setTag("hazmat:tunnel_cat", "E");
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(HazmatTunnel.E, hazTunnelEnc.getEnum(false, intsRef));
}
Also used : IntsRef(com.graphhopper.storage.IntsRef) ReaderWay(com.graphhopper.reader.ReaderWay) Test(org.junit.jupiter.api.Test)

Example 75 with ReaderWay

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

the class OSMHazmatTunnelParserTest method testHazmatSubtags.

@Test
public void testHazmatSubtags() {
    IntsRef intsRef = em.createEdgeFlags();
    ReaderWay readerWay = new ReaderWay(1);
    readerWay.setTag("tunnel", "yes");
    readerWay.setTag("hazmat:A", "no");
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(HazmatTunnel.A, hazTunnelEnc.getEnum(false, intsRef));
    intsRef = em.createEdgeFlags();
    readerWay = new ReaderWay(1);
    readerWay.setTag("tunnel", "yes");
    readerWay.setTag("hazmat:B", "no");
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(HazmatTunnel.B, hazTunnelEnc.getEnum(false, intsRef));
    intsRef = em.createEdgeFlags();
    readerWay = new ReaderWay(1);
    readerWay.setTag("tunnel", "yes");
    readerWay.setTag("hazmat:C", "no");
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(HazmatTunnel.C, hazTunnelEnc.getEnum(false, intsRef));
    intsRef = em.createEdgeFlags();
    readerWay = new ReaderWay(1);
    readerWay.setTag("tunnel", "yes");
    readerWay.setTag("hazmat:D", "no");
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(HazmatTunnel.D, hazTunnelEnc.getEnum(false, intsRef));
    intsRef = em.createEdgeFlags();
    readerWay = new ReaderWay(1);
    readerWay.setTag("tunnel", "yes");
    readerWay.setTag("hazmat:E", "no");
    parser.handleWayTags(intsRef, readerWay, relFlags);
    assertEquals(HazmatTunnel.E, hazTunnelEnc.getEnum(false, intsRef));
}
Also used : IntsRef(com.graphhopper.storage.IntsRef) ReaderWay(com.graphhopper.reader.ReaderWay) 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