Search in sources :

Example 1 with RoadEnvironment

use of com.graphhopper.routing.ev.RoadEnvironment 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 2 with RoadEnvironment

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

the class OSMRoadEnvironmentParserTest method ferry.

@Test
void ferry() {
    OSMRoadEnvironmentParser parser = new OSMRoadEnvironmentParser();
    CarFlagEncoder carEncoder = new CarFlagEncoder();
    EncodingManager em = new EncodingManager.Builder().add(carEncoder).add(parser).build();
    EnumEncodedValue<RoadEnvironment> roadEnvironmentEnc = em.getEnumEncodedValue(RoadEnvironment.KEY, RoadEnvironment.class);
    IntsRef edgeFlags = em.createEdgeFlags();
    ReaderWay way = new ReaderWay(0);
    way.setTag("route", "shuttle_train");
    parser.handleWayTags(edgeFlags, way, em.createRelationFlags());
    RoadEnvironment roadEnvironment = roadEnvironmentEnc.getEnum(false, edgeFlags);
    assertEquals(RoadEnvironment.FERRY, roadEnvironment);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) RoadEnvironment(com.graphhopper.routing.ev.RoadEnvironment) IntsRef(com.graphhopper.storage.IntsRef) ReaderWay(com.graphhopper.reader.ReaderWay) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Test(org.junit.jupiter.api.Test)

Example 3 with RoadEnvironment

use of com.graphhopper.routing.ev.RoadEnvironment 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

RoadEnvironment (com.graphhopper.routing.ev.RoadEnvironment)3 RoadClass (com.graphhopper.routing.ev.RoadClass)2 IntsRef (com.graphhopper.storage.IntsRef)2 Test (org.junit.jupiter.api.Test)2 IntArrayList (com.carrotsearch.hppc.IntArrayList)1 ReaderWay (com.graphhopper.reader.ReaderWay)1 EnumEncodedValue (com.graphhopper.routing.ev.EnumEncodedValue)1 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)1 EncodingManager (com.graphhopper.routing.util.EncodingManager)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