Bus flag encoder on graphhopper.com

Aha! My Java skills are shocking - I messed up the constructor inheritance. Also, I had to remove “no” as a restricted value; access == no doesn’t mean that psv != yes. Here is my bus code, for anyone else that might find it useful:

// vim: set expandtab:

package com.graphhopper.routing.util;

import com.graphhopper.reader.OSMRelation;
import com.graphhopper.reader.OSMWay;
import com.graphhopper.reader.osm.conditional.ConditionalTagsInspector;
import com.graphhopper.reader.osm.conditional.DateRangeParser;
import com.graphhopper.util.Helper;
import com.graphhopper.util.PMap;

import java.util.*;


public class BusFlagEncoder extends CarFlagEncoder
{
    public BusFlagEncoder()
    {
        this(5, 5, 0);
    }

    public BusFlagEncoder(PMap properties)
    {
        this(
                (int) properties.getLong("speed_bits", 5),
                properties.getDouble("speed_factor", 5),
                properties.getBool("turn_costs", false) ? 1 : 0
        );
        this.properties = properties;
        this.setBlockFords(properties.getBool("block_fords", true));
    }

    public BusFlagEncoder(String propertiesStr)
    {
        this(new PMap(propertiesStr));
    }

    public BusFlagEncoder(int speedBits, double speedFactor, int maxTurnCosts)
    {
        super(speedBits, speedFactor, maxTurnCosts);
        restrictions.remove("motorcar");
        restrictions.add("psv");
        restrictions.add("bus");

        restrictedValues.remove("no");
        restrictedValues.remove("private");

        absoluteBarriers.remove("bus_trap");
        absoluteBarriers.remove("sump_buster");
    }

    @Override
    public String toString()
    {
        return "bus";
    }
}
1 Like