com.graphhopper.routing.util.parsers.ModeAccessParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of graphhopper-core Show documentation
Show all versions of graphhopper-core Show documentation
GraphHopper is a fast and memory efficient Java road routing engine
working seamlessly with OpenStreetMap data.
package com.graphhopper.routing.util.parsers;
import com.graphhopper.reader.ReaderWay;
import com.graphhopper.routing.ev.BooleanEncodedValue;
import com.graphhopper.routing.ev.EdgeIntAccess;
import com.graphhopper.routing.util.FerrySpeedCalculator;
import com.graphhopper.routing.util.TransportationMode;
import com.graphhopper.storage.IntsRef;
import java.util.*;
import static com.graphhopper.routing.util.parsers.OSMTemporalAccessParser.hasTemporalRestriction;
public class ModeAccessParser implements TagParser {
private final static Set onewaysForward = new HashSet<>(Arrays.asList("yes", "true", "1"));
private final Set restrictedValues;
private final List restrictionKeys;
private final List vehicleForward;
private final List vehicleBackward;
private final List ignoreOnewayKeys;
private final BooleanEncodedValue accessEnc;
private final BooleanEncodedValue roundaboutEnc;
public ModeAccessParser(TransportationMode mode, BooleanEncodedValue accessEnc, BooleanEncodedValue roundaboutEnc, List restrictions) {
this.accessEnc = accessEnc;
this.roundaboutEnc = roundaboutEnc;
restrictionKeys = OSMRoadAccessParser.toOSMRestrictions(mode);
vehicleForward = restrictionKeys.stream().map(r -> r + ":forward").toList();
vehicleBackward = restrictionKeys.stream().map(r -> r + ":backward").toList();
ignoreOnewayKeys = restrictionKeys.stream().map(r -> "oneway:" + r).toList();
restrictedValues = new HashSet<>(restrictions.isEmpty() ? Arrays.asList("no", "restricted", "military", "emergency") : restrictions);
if (restrictedValues.contains(""))
throw new IllegalArgumentException("restriction values cannot contain empty string");
}
@Override
public void handleWayTags(int edgeId, EdgeIntAccess edgeIntAccess, ReaderWay way, IntsRef relationFlags) {
int firstIndex = way.getFirstIndex(restrictionKeys);
String firstValue = firstIndex < 0 ? "" : way.getTag(restrictionKeys.get(firstIndex), "");
if (restrictedValues.contains(firstValue) && !hasTemporalRestriction(way, firstIndex, restrictionKeys))
return;
if (way.hasTag("gh:barrier_edge") && way.hasTag("node_tags")) {
List