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)));
}
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);
}
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;
}
Aggregations