TagParser HelperMethods

In one of my encoders I would like to get the RoadClass of the current ReaderWay in the method EncodingManager.Access getAccess(ReaderWay way). However, TagParsers are called after getAccess.

My current solution would be to do something like:

public class OSMRoadClassParser implements TagParser {


    public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay readerWay, boolean ferry, IntsRef relationFlags) {
        if (ferry)
            return edgeFlags;

        String roadClassTag = readerWay.getTag("highway");
        if (roadClassTag == null)
            return edgeFlags;

        RoadClass roadClass = getRoadClass(roadClassTag);

        if (roadClass != OTHER)
            roadClassEnc.setEnum(false, edgeFlags, roadClass);
        return edgeFlags;

    public static RoadClass getRoadClass(String roadClassTag) {
        RoadClass roadClass = RoadClass.find(roadClassTag);
        if (roadClass == OTHER && roadClassTag.endsWith("_link"))
            roadClass = RoadClass.find(roadClassTag.substring(0, roadClassTag.length() - 5));

        return roadClass;

This allows me to call OSMRoadClassParser.getRoadClass(way.getTag("highway", "")) in my encoder.

A similar “issue” exists for the CarFlagEncoder and fords:

        // do not drive street cars into fords
        if (isBlockFords() && ("ford".equals(highwayValue) || way.hasTag("ford")))
            return EncodingManager.Access.CAN_SKIP;

Here it might be convenient to do something like OSMRoadEnvironmentParser.getRoadEnvironment(way) == FORD.

You can surely introduce these helper methods to reduce code duplication, but I have not done this yet to reduce coupling of the parsers. Surely sometimes there are dependencies (see e.g. SpatialRuleParser and OSMRoadAccessParser) and the current workaround is to rely on the processing order and put intermediate results into readerWay which is suboptimal.

Oh, and it seems there is a bug in RoadAccessParser as we do

RoadClass roadClass = RoadClass.find(readerWay.getTag("highway", ""));
accessValue = spatialRuleSet.getAccess(roadClass, TransportationMode.MOTOR_VEHICLE, YES);

and do not consider the road class links there. And also the TransportationMode.MOTOR_VEHICLE does not seem to fit … probably this is for another issue.

Furthermore I hope we can somehow get rid of getAccess (e.g. when we remove the FlagEncoders) as it IMO the task of the Weighting to block access and a OSM-way-prefiltering should happen without duplicating most of the handleWayTags.

Powered by Discourse