Example of edge filter for road snapping

I am wondering if there are examples for using custom edge filters for road snapping. Currently I am using ALL_EDGES:

QueryResult queryResult = hopper.getLocationIndex().findClosest(latitude, longitude, EdgeFilter.ALL_EDGES);

Examples for custom edge filters would be snaps based on OSM tags or edges of certain lengths / max velocities.

At least filtering by edge distance is very simple:

index.findClosest(latitude, longitude, edgeState -> edgeState.getDistance() > 1000);

For OSM tags, velocity etc. you need to read the edge properties using FlagEncoder and/or EncodedValue. For example speed:

double speedFwd = edgeState.get(encoder.getAverageSpeedEnc());
double speedBwd = edgeState.getReverse(encoder.getAverageSpeedEnc());
1 Like

See also https://github.com/graphhopper/graphhopper/pull/1644

1 Like