5

I am trying to modify CarFlagEncoder.java so that GraphHopper will use two pieces of road which it does not by default:

http://www.openstreetmap.org/way/181263007
http://www.openstreetmap.org/way/37720333

Am I right in saying that to allow access to this road it is as simple as removing restrictedValues.add("private") from the public CarFlagEncoder( int speedBits, double speedFactor, int maxTurnCosts ) method?

public CarFlagEncoder( int speedBits, double speedFactor, int maxTurnCosts )
{
    super(speedBits, speedFactor, maxTurnCosts);
    restrictions.addAll(Arrays.asList("motorcar", "motor_vehicle", "vehicle", "access"));
    restrictedValues.add("private");
    restrictedValues.add("agricultural");
    restrictedValues.add("forestry");
    restrictedValues.add("no");
    restrictedValues.add("restricted");
    restrictedValues.add("delivery");
    restrictedValues.add("military");

It's either there or in the acceptWay method that I need to modify:

@Override
public long acceptWay( OSMWay way )
{
    String highwayValue = way.getTag("highway");
    if (highwayValue == null)
    {
        if (way.hasTag("route", ferries))
        {
            String motorcarTag = way.getTag("motorcar");
            if (motorcarTag == null)
                motorcarTag = way.getTag("motor_vehicle");

            if (motorcarTag == null && !way.hasTag("foot") && !way.hasTag("bicycle") || "yes".equals(motorcarTag))
                return acceptBit | ferryBit;
        }
        return 0;
    }

    if ("track".equals(highwayValue))
    {
        String tt = way.getTag("tracktype");
        if (tt != null && !tt.equals("grade1") && !tt.equals("grade2") && !tt.equals("grade3"))
            return 0;
    }

    if (!defaultSpeedMap.containsKey(highwayValue))
        return 0;

    if (way.hasTag("impassable", "yes") || way.hasTag("status", "impassable"))
        return 0;

    // multiple restrictions needs special handling compared to foot and bike, see also motorcycle
    String firstValue = way.getFirstPriorityTag(restrictions);
    if (!firstValue.isEmpty())
    {
        if (restrictedValues.contains(firstValue))
            return 0;
        if (intendedValues.contains(firstValue))
            return acceptBit;
    }

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

    // do not drive cars over railways (sometimes incorrectly mapped!)
    if (way.hasTag("railway") && !way.hasTag("railway", acceptedRailways))
        return 0;

    return acceptBit;
}

If anyone can please explain the best way to do this I would be very appreciative.

user3605739
  • 495
  • 3
  • 6
  • 17
  • It would be useful to post your lines of code in the context of the surrounding code so people can better help you. – cryptic_star Sep 23 '15 at 13:29
  • 2
    @cryptic_star Thank you, I have added two samples where I think the code will need modifying to achieve what I have asked in the question – user3605739 Sep 23 '15 at 13:32
  • 1
    Sounds like removing `restrictedValues.add("private")` would work. Why don't you just try it? – scai Sep 23 '15 at 13:58
  • 1
    @scai Good question - I did, and it didn't work. :( – user3605739 Sep 23 '15 at 14:01
  • @user3605739 There is also a barrier at the end of way 37720333 which could also be the reason for taking a different route. You can test this by setting the end point somewhere along this way. – scai Sep 23 '15 at 14:19
  • 3
    See `handleNodeTags()` under `AbstractFlagEncoder.java`. For motorcar `barrier=gate` is a `potentialBarriers`, and routing through it requires one of the tags `motorcar`/`motor_vehicle`/`vehicle`/`access` to be `yes` or `permissive`. – headuck Sep 23 '15 at 19:37
  • 1
    Please avoid posting to forum and stackoverflow https://discuss.graphhopper.com/t/modify-carflagencoder-to-allow-type-of-road/147 – Karussell Sep 24 '15 at 07:36

0 Answers0