Search in sources :

Example 1 with RoadClass

use of com.graphhopper.routing.ev.RoadClass in project graphhopper by graphhopper.

the class PriorityRoutingTest method maxSpeedEdge.

private EdgeIteratorState maxSpeedEdge(EncodingManager em, GraphHopperStorage graph, int p, int q, FlagEncoder encoder, double prio) {
    BooleanEncodedValue accessEnc = encoder.getAccessEnc();
    DecimalEncodedValue speedEnc = encoder.getAverageSpeedEnc();
    DecimalEncodedValue priorityEnc = em.getDecimalEncodedValue(EncodingManager.getKey(encoder, "priority"));
    EnumEncodedValue<RoadClass> roadClassEnc = em.getEnumEncodedValue(RoadClass.KEY, RoadClass.class);
    return graph.edge(p, q).set(accessEnc, true).set(speedEnc, encoder.getMaxSpeed()).set(priorityEnc, prio).set(roadClassEnc, RoadClass.MOTORWAY).setDistance(calcDist(graph, p, q));
}
Also used : BooleanEncodedValue(com.graphhopper.routing.ev.BooleanEncodedValue) DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) RoadClass(com.graphhopper.routing.ev.RoadClass)

Example 2 with RoadClass

use of com.graphhopper.routing.ev.RoadClass in project graphhopper by graphhopper.

the class OSMRoadClassParser method handleWayTags.

@Override
public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay readerWay, IntsRef relationFlags) {
    String roadClassTag = readerWay.getTag("highway");
    if (roadClassTag == null)
        return edgeFlags;
    RoadClass roadClass = RoadClass.find(roadClassTag);
    if (roadClass == OTHER && roadClassTag.endsWith("_link"))
        roadClass = RoadClass.find(roadClassTag.substring(0, roadClassTag.length() - 5));
    if (roadClass != OTHER)
        roadClassEnc.setEnum(false, edgeFlags, roadClass);
    return edgeFlags;
}
Also used : RoadClass(com.graphhopper.routing.ev.RoadClass)

Example 3 with RoadClass

use of com.graphhopper.routing.ev.RoadClass in project graphhopper by graphhopper.

the class SnapPreventionEdgeFilterTest method accept.

@Test
public void accept() {
    EdgeFilter trueFilter = edgeState -> true;
    EncodingManager em = new EncodingManager.Builder().build();
    EnumEncodedValue<RoadClass> rcEnc = em.getEnumEncodedValue(RoadClass.KEY, RoadClass.class);
    EnumEncodedValue<RoadEnvironment> reEnc = em.getEnumEncodedValue(RoadEnvironment.KEY, RoadEnvironment.class);
    SnapPreventionEdgeFilter filter = new SnapPreventionEdgeFilter(trueFilter, rcEnc, reEnc, Arrays.asList("motorway", "ferry"));
    IntsRef intsRef = em.createEdgeFlags();
    assertTrue(filter.accept(GHUtility.createMockedEdgeIteratorState(1, intsRef)));
    reEnc.setEnum(false, intsRef, RoadEnvironment.FERRY);
    assertFalse(filter.accept(GHUtility.createMockedEdgeIteratorState(1, intsRef)));
    reEnc.setEnum(false, intsRef, RoadEnvironment.FORD);
    assertTrue(filter.accept(GHUtility.createMockedEdgeIteratorState(1, intsRef)));
    rcEnc.setEnum(false, intsRef, RoadClass.RESIDENTIAL);
    assertTrue(filter.accept(GHUtility.createMockedEdgeIteratorState(1, intsRef)));
    rcEnc.setEnum(false, intsRef, RoadClass.MOTORWAY);
    assertFalse(filter.accept(GHUtility.createMockedEdgeIteratorState(1, intsRef)));
}
Also used : RoadEnvironment(com.graphhopper.routing.ev.RoadEnvironment) Test(org.junit.jupiter.api.Test) Arrays(java.util.Arrays) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) RoadClass(com.graphhopper.routing.ev.RoadClass) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) IntsRef(com.graphhopper.storage.IntsRef) GHUtility(com.graphhopper.util.GHUtility) EnumEncodedValue(com.graphhopper.routing.ev.EnumEncodedValue) RoadEnvironment(com.graphhopper.routing.ev.RoadEnvironment) RoadClass(com.graphhopper.routing.ev.RoadClass) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 4 with RoadClass

use of com.graphhopper.routing.ev.RoadClass in project graphhopper by graphhopper.

the class ViaRouting method lookup.

/**
 * @throws MultiplePointsNotFoundException in case one or more points could not be resolved
 */
public static List<Snap> lookup(EncodedValueLookup lookup, List<GHPoint> points, EdgeFilter snapFilter, LocationIndex locationIndex, List<String> snapPreventions, List<String> pointHints, DirectedEdgeFilter directedSnapFilter, List<Double> headings) {
    if (points.size() < 2)
        throw new IllegalArgumentException("At least 2 points have to be specified, but was:" + points.size());
    final EnumEncodedValue<RoadClass> roadClassEnc = lookup.getEnumEncodedValue(RoadClass.KEY, RoadClass.class);
    final EnumEncodedValue<RoadEnvironment> roadEnvEnc = lookup.getEnumEncodedValue(RoadEnvironment.KEY, RoadEnvironment.class);
    EdgeFilter strictEdgeFilter = snapPreventions.isEmpty() ? snapFilter : new SnapPreventionEdgeFilter(snapFilter, roadClassEnc, roadEnvEnc, snapPreventions);
    List<Snap> snaps = new ArrayList<>(points.size());
    IntArrayList pointsNotFound = new IntArrayList();
    for (int placeIndex = 0; placeIndex < points.size(); placeIndex++) {
        GHPoint point = points.get(placeIndex);
        Snap snap = null;
        if (placeIndex < headings.size() && !Double.isNaN(headings.get(placeIndex))) {
            if (!pointHints.isEmpty() && !Helper.isEmpty(pointHints.get(placeIndex)))
                throw new IllegalArgumentException("Cannot specify heading and point_hint at the same time. " + "Make sure you specify either an empty point_hint (String) or a NaN heading (double) for point " + placeIndex);
            snap = locationIndex.findClosest(point.lat, point.lon, new HeadingEdgeFilter(directedSnapFilter, headings.get(placeIndex), point));
        } else if (!pointHints.isEmpty()) {
            snap = locationIndex.findClosest(point.lat, point.lon, new NameSimilarityEdgeFilter(strictEdgeFilter, pointHints.get(placeIndex), point, 100));
        } else if (!snapPreventions.isEmpty()) {
            snap = locationIndex.findClosest(point.lat, point.lon, strictEdgeFilter);
        }
        if (snap == null || !snap.isValid())
            snap = locationIndex.findClosest(point.lat, point.lon, snapFilter);
        if (!snap.isValid())
            pointsNotFound.add(placeIndex);
        snaps.add(snap);
    }
    if (!pointsNotFound.isEmpty())
        throw new MultiplePointsNotFoundException(pointsNotFound);
    return snaps;
}
Also used : ArrayList(java.util.ArrayList) IntArrayList(com.carrotsearch.hppc.IntArrayList) RoadClass(com.graphhopper.routing.ev.RoadClass) Snap(com.graphhopper.storage.index.Snap) GHPoint(com.graphhopper.util.shapes.GHPoint) RoadEnvironment(com.graphhopper.routing.ev.RoadEnvironment) IntArrayList(com.carrotsearch.hppc.IntArrayList) GHPoint(com.graphhopper.util.shapes.GHPoint)

Aggregations

RoadClass (com.graphhopper.routing.ev.RoadClass)4 RoadEnvironment (com.graphhopper.routing.ev.RoadEnvironment)2 IntArrayList (com.carrotsearch.hppc.IntArrayList)1 BooleanEncodedValue (com.graphhopper.routing.ev.BooleanEncodedValue)1 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)1 EnumEncodedValue (com.graphhopper.routing.ev.EnumEncodedValue)1 IntsRef (com.graphhopper.storage.IntsRef)1 Snap (com.graphhopper.storage.index.Snap)1 GHUtility (com.graphhopper.util.GHUtility)1 GHPoint (com.graphhopper.util.shapes.GHPoint)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 Test (org.junit.jupiter.api.Test)1