private int handlePriority(ReaderWay way, long relationFlags) { String highway = way.getTag("highway", ""); if (avoidSet.contains(highway)) { return PriorityCode.WORST.getValue(); } else if (preferSet.contains(highway)) { return PriorityCode.BEST.getValue(); } return PriorityCode.UNCHANGED.getValue(); }
public HikeFlagEncoder(int speedBits, double speedFactor) { super(speedBits, speedFactor); hikingNetworkToCode.put("iwn", BEST.getValue()); hikingNetworkToCode.put("nwn", BEST.getValue()); hikingNetworkToCode.put("rwn", VERY_NICE.getValue()); hikingNetworkToCode.put("lwn", VERY_NICE.getValue()); init(); }
@Override void collect(ReaderWay way, double wayTypeSpeed, TreeMap<Double, Integer> weightToPrioMap) { super.collect(way, wayTypeSpeed, weightToPrioMap); String highway = way.getTag("highway"); if ("track".equals(highway)) { String trackType = way.getTag("tracktype"); if ("grade1".equals(trackType)) weightToPrioMap.put(50d, UNCHANGED.getValue()); else if (trackType == null) weightToPrioMap.put(90d, PREFER.getValue()); else if (trackType.startsWith("grade")) weightToPrioMap.put(100d, VERY_NICE.getValue()); } }
@Override void collect(ReaderWay way, double wayTypeSpeed, TreeMap<Double, Integer> weightToPrioMap) { super.collect(way, wayTypeSpeed, weightToPrioMap); String highway = way.getTag("highway"); if ("service".equals(highway)) { weightToPrioMap.put(40d, UNCHANGED.getValue()); } else if ("track".equals(highway)) { String trackType = way.getTag("tracktype"); if ("grade1".equals(trackType)) weightToPrioMap.put(110d, PREFER.getValue()); else if (trackType == null || trackType.startsWith("grade")) weightToPrioMap.put(110d, AVOID_AT_ALL_COSTS.getValue()); } }
protected int handlePriority(ReaderWay way, int priorityFromRelation) { TreeMap<Double, Integer> weightToPrioMap = new TreeMap<>(); if (priorityFromRelation == 0) weightToPrioMap.put(0d, UNCHANGED.getValue()); else weightToPrioMap.put(110d, priorityFromRelation); collect(way, weightToPrioMap); // pick priority with biggest order value return weightToPrioMap.lastEntry().getValue(); }
@Override void collect(ReaderWay way, TreeMap<Double, Integer> weightToPrioMap) { String highway = way.getTag("highway"); if (way.hasTag("foot", "designated")) weightToPrioMap.put(100d, PREFER.getValue()); double maxSpeed = getMaxSpeed(way); if (safeHighwayTags.contains(highway) || maxSpeed > 0 && maxSpeed <= 20) { weightToPrioMap.put(40d, PREFER.getValue()); if (way.hasTag("tunnel", intendedValues)) { if (way.hasTag("sidewalk", sidewalksNoValues)) weightToPrioMap.put(40d, REACH_DEST.getValue()); else weightToPrioMap.put(40d, UNCHANGED.getValue()); } } else if (maxSpeed > 50 || avoidHighwayTags.contains(highway)) { if (way.hasTag("sidewalk", sidewalksNoValues)) weightToPrioMap.put(45d, WORST.getValue()); else weightToPrioMap.put(45d, REACH_DEST.getValue()); } if (way.hasTag("bicycle", "official") || way.hasTag("bicycle", "designated")) weightToPrioMap.put(44d, AVOID_IF_POSSIBLE.getValue()); }
/** * In this method we prefer cycleways or roads with designated bike access and avoid big roads * or roads with trams or pedestrian. * <p> * * @return new priority based on priorityFromRelation and on the tags in ReaderWay. */ protected int handlePriority(ReaderWay way, double wayTypeSpeed, int priorityFromRelation) { TreeMap<Double, Integer> weightToPrioMap = new TreeMap<>(); if (priorityFromRelation == 0) weightToPrioMap.put(0d, UNCHANGED.getValue()); else weightToPrioMap.put(110d, priorityFromRelation); collect(way, wayTypeSpeed, weightToPrioMap); // pick priority with biggest order value return weightToPrioMap.lastEntry().getValue(); }
@Override public double getDouble(long flags, int key) { switch (key) { case PriorityWeighting.KEY: return (double) priorityWayEncoder.getValue(flags) / BEST.getValue(); default: return super.getDouble(flags, key); } }
/** * @param weightToPrioMap associate a weight with every priority. This sorted map allows * subclasses to 'insert' more important priorities as well as overwrite determined priorities. */ void collect(ReaderWay way, TreeMap<Double, Integer> weightToPrioMap) { String highway = way.getTag("highway"); if (way.hasTag("foot", "designated")) weightToPrioMap.put(100d, PREFER.getValue()); double maxSpeed = getMaxSpeed(way); if (safeHighwayTags.contains(highway) || maxSpeed > 0 && maxSpeed <= 20) { weightToPrioMap.put(40d, PREFER.getValue()); if (way.hasTag("tunnel", intendedValues)) { if (way.hasTag("sidewalk", sidewalksNoValues)) weightToPrioMap.put(40d, AVOID_IF_POSSIBLE.getValue()); else weightToPrioMap.put(40d, UNCHANGED.getValue()); } } else if (maxSpeed > 50 || avoidHighwayTags.contains(highway)) { if (!way.hasTag("sidewalk", sidewalkValues)) weightToPrioMap.put(45d, AVOID_IF_POSSIBLE.getValue()); } if (way.hasTag("bicycle", "official") || way.hasTag("bicycle", "designated")) weightToPrioMap.put(44d, AVOID_IF_POSSIBLE.getValue()); }
@Override public double getDouble(long flags, int key) { switch (key) { case PriorityWeighting.KEY: return (double) priorityWayEncoder.getValue(flags) / BEST.getValue(); default: return super.getDouble(flags, key); } }
@Override public long handleRelationTags(ReaderRelation relation, long oldRelationFlags) { int code = 0; if (relation.hasTag("route", "bicycle")) { Integer val = bikeNetworkToCode.get(relation.getTag("network")); if (val != null) code = val; else code = PriorityCode.PREFER.getValue(); // Assume priority of network "lcn" as bicycle route default } else if (relation.hasTag("route", "ferry")) { code = AVOID_IF_POSSIBLE.getValue(); } int oldCode = (int) relationCodeEncoder.getValue(oldRelationFlags); if (oldCode < code) return relationCodeEncoder.setValue(0, code); return oldRelationFlags; }
@Override public double getDouble(long flags, int key) { switch (key) { case PriorityWeighting.KEY: return (double) priorityWayEncoder.getValue(flags) / BEST.getValue(); case MotorcycleFlagEncoder.CURVATURE_KEY: return (double) curvatureEncoder.getValue(flags) / 10; default: return super.getDouble(flags, key); } }
if (way.hasTag("bicycle", "designated") || way.hasTag("bicycle", "official")) { if ("path".equals(highway)) weightToPrioMap.put(100d, VERY_NICE.getValue()); else weightToPrioMap.put(100d, PREFER.getValue()); weightToPrioMap.put(100d, PREFER.getValue()); else weightToPrioMap.put(100d, VERY_NICE.getValue()); if (preferHighwayTags.contains(highway) || maxSpeed > 0 && maxSpeed <= 30) { if (maxSpeed < avoidSpeedLimit) { weightToPrioMap.put(40d, PREFER.getValue()); if (way.hasTag("tunnel", intendedValues)) weightToPrioMap.put(40d, UNCHANGED.getValue()); weightToPrioMap.put(50d, REACH_DEST.getValue()); if (way.hasTag("tunnel", intendedValues)) weightToPrioMap.put(50d, AVOID_AT_ALL_COSTS.getValue()); || way.hasTag("bicycle", "use_sidepath") || "parking_aisle".equals(service)) { int pushingSectionPrio = AVOID_IF_POSSIBLE.getValue(); if (way.hasTag("bicycle", "yes") || way.hasTag("bicycle", "permissive")) pushingSectionPrio = PREFER.getValue(); if (way.hasTag("bicycle", "designated") || way.hasTag("bicycle", "official")) pushingSectionPrio = VERY_NICE.getValue(); if (way.hasTag("foot", "yes")) { pushingSectionPrio = Math.max(pushingSectionPrio - 1, WORST.getValue());
@Override public long handleRelationTags(ReaderRelation relation, long oldRelationFlags) { oldRelationFlags = super.handleRelationTags(relation, oldRelationFlags); int code = 0; if (relation.hasTag("route", "mtb")) code = PREFER.getValue(); int oldCode = (int) relationCodeEncoder.getValue(oldRelationFlags); if (oldCode < code) return relationCodeEncoder.setValue(0, code); return oldRelationFlags; }
@Override public long handleRelationTags(ReaderRelation relation, long oldRelationFlags) { int code = 0; if (relation.hasTag("route", "hiking") || relation.hasTag("route", "foot")) { Integer val = hikingNetworkToCode.get(relation.getTag("network")); if (val != null) code = val; else code = hikingNetworkToCode.get("lwn"); } else if (relation.hasTag("route", "ferry")) { code = PriorityCode.AVOID_IF_POSSIBLE.getValue(); } int oldCode = (int) relationCodeEncoder.getValue(oldRelationFlags); if (oldCode < code) return relationCodeEncoder.setValue(0, code); return oldRelationFlags; }
@Test public void testAvoidTunnel() { ReaderWay osmWay = new ReaderWay(1); osmWay.setTag("highway", "residential"); assertPriority(PREFER.getValue(), osmWay); osmWay.setTag("tunnel", "yes"); assertPriority(UNCHANGED.getValue(), osmWay); osmWay.setTag("highway", "secondary"); osmWay.setTag("tunnel", "yes"); assertPriority(AVOID_AT_ALL_COSTS.getValue(), osmWay); osmWay.setTag("bicycle", "designated"); assertPriority(PREFER.getValue(), osmWay); }
@Test public void testHandleWayTagsCallsHandlePriority() { ReaderWay osmWay = new ReaderWay(1); osmWay.setTag("highway", "cycleway"); long encoded = encoder.handleWayTags(osmWay, encoder.acceptBit, 0); assertEquals((double) VERY_NICE.getValue() / BEST.getValue(), encoder.getDouble(encoded, PriorityWeighting.KEY), 1e-3); }
@Test public void testTram() { ReaderWay way = new ReaderWay(1); // very dangerous way.setTag("highway", "secondary"); way.setTag("railway", "tram"); assertPriority(AVOID_AT_ALL_COSTS.getValue(), way); // should be safe now way.setTag("bicycle", "designated"); assertPriority(PREFER.getValue(), way); }
@Test @Override public void testAvoidTunnel() { // tunnel is not that bad for racing bike ReaderWay osmWay = new ReaderWay(1); osmWay.setTag("highway", "residential"); osmWay.setTag("tunnel", "yes"); assertPriority(UNCHANGED.getValue(), osmWay); osmWay.setTag("highway", "secondary"); osmWay.setTag("tunnel", "yes"); assertPriority(UNCHANGED.getValue(), osmWay); osmWay.setTag("bicycle", "designated"); assertPriority(PREFER.getValue(), osmWay); }