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 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 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 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); } }
@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; }
@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); }
@Test public void testPriority() { long flags = encoder.priorityWayEncoder.setValue(0, PriorityCode.BEST.getValue()); assertEquals(1, encoder.getDouble(flags, PriorityWeighting.KEY), 1e-3); flags = encoder.priorityWayEncoder.setValue(0, PriorityCode.AVOID_IF_POSSIBLE.getValue()); assertEquals(3d / 7d, encoder.getDouble(flags, PriorityWeighting.KEY), 1e-3); }
@Test @Override public void testService() { ReaderWay way = new ReaderWay(1); way.setTag("highway", "service"); assertEquals(12, encoder.getSpeed(way)); assertPriority(UNCHANGED.getValue(), way); way.setTag("service", "parking_aisle"); assertEquals(6, encoder.getSpeed(way)); assertPriority(AVOID_IF_POSSIBLE.getValue(), way); }
@Test public void testAvoidMotorway() { ReaderWay osmWay = new ReaderWay(1); osmWay.setTag("highway", "motorway"); osmWay.setTag("bicycle", "yes"); assertPriority(REACH_DEST.getValue(), osmWay); }
@Test public void testService() { ReaderWay way = new ReaderWay(1); way.setTag("highway", "service"); assertEquals(14, encoder.getSpeed(way)); assertPriority(PREFER.getValue(), way); way.setTag("service", "parking_aisle"); assertEquals(6, encoder.getSpeed(way)); assertPriority(AVOID_IF_POSSIBLE.getValue(), way); }
@Test public void testUnchangedRelationShouldNotInfluencePriority() { ReaderWay osmWay = new ReaderWay(1); osmWay.setTag("highway", "secondary"); ReaderRelation osmRel = new ReaderRelation(1); osmRel.setTag("description", "something"); long relFlags = encoder.handleRelationTags(osmRel, 0); assertPriority(REACH_DEST.getValue(), osmWay, relFlags); }
@Test public void testPreferenceForSlowSpeed() { ReaderWay osmWay = new ReaderWay(1); osmWay.setTag("highway", "tertiary"); assertEquals(30, encoder.getSpeed(encoder.setSpeed(0, encoder.applyMaxSpeed(osmWay, 49))), 1e-1); assertPriority(PREFER.getValue(), osmWay); }