|
14 | 14 | importstaticcom.graphhopper.routing.util.parsers.AbstractAccessParser.INTENDED; |
15 | 15 |
|
16 | 16 | publicabstractclassBikeCommonPriorityParserimplementsTagParser { |
| 17 | +privatestaticfinalSet<String>CYCLEWAY_KEYS =Set.of("cycleway","cycleway:left","cycleway:both","cycleway:right"); |
17 | 18 |
|
18 | | -//Bicycle tracks subject to compulsory use in Germany and Poland (https://wiki.openstreetmap.org/wiki/DE:Key:cycleway) |
| 19 | +//rare use case when a bicycle lane has access tag |
19 | 20 | privatestaticfinalList<String>CYCLEWAY_BICYCLE_KEYS =List.of("cycleway:bicycle","cycleway:both:bicycle","cycleway:left:bicycle","cycleway:right:bicycle"); |
20 | 21 |
|
21 | | -//Pushing section highways are parts where you need to get off your bike and push it (German: Schiebestrecke) |
| 22 | +//pushing section highways are parts where you need to get off your bike and push it |
22 | 23 | protectedfinalHashSet<String>pushingSectionsHighways =newHashSet<>(); |
23 | 24 | protectedfinalSet<String>preferHighwayTags =newHashSet<>(); |
24 | 25 | protectedfinalMap<String,PriorityCode>avoidHighwayTags =newHashMap<>(); |
@@ -76,41 +77,34 @@ protected BikeCommonPriorityParser(DecimalEncodedValue priorityEnc, DecimalEncod |
76 | 77 | @Override |
77 | 78 | publicvoidhandleWayTags(intedgeId,EdgeIntAccessedgeIntAccess,ReaderWayway,IntsRefrelationFlags) { |
78 | 79 | StringhighwayValue =way.getTag("highway"); |
79 | | -IntegerpriorityFromRelation =null; |
80 | | -switch (bikeRouteEnc.getEnum(false,edgeId,edgeIntAccess)) { |
81 | | -caseINTERNATIONAL,NATIONAL ->priorityFromRelation =BEST.getValue(); |
82 | | -caseREGIONAL,LOCAL ->priorityFromRelation =VERY_NICE.getValue(); |
| 80 | +PriorityCodepriorityFromRelation =null; |
| 81 | +RouteNetworkbikeRouteNetwork =bikeRouteEnc.getEnum(false,edgeId,edgeIntAccess); |
| 82 | +switch (bikeRouteNetwork) { |
| 83 | +caseINTERNATIONAL,NATIONAL ->priorityFromRelation =BEST; |
| 84 | +caseREGIONAL,LOCAL ->priorityFromRelation =VERY_NICE; |
83 | 85 | } |
84 | 86 |
|
85 | 87 | if (highwayValue ==null) { |
86 | 88 | if (FerrySpeedCalculator.isFerry(way)) { |
87 | | -priorityFromRelation =SLIGHT_AVOID.getValue(); |
| 89 | +priorityFromRelation =SLIGHT_AVOID; |
88 | 90 | }else { |
89 | 91 | return; |
90 | 92 | } |
91 | 93 | } |
92 | 94 |
|
93 | | -doublemaxSpeed =Math.max(avgSpeedEnc.getDecimal(false,edgeId,edgeIntAccess),avgSpeedEnc.getDecimal(true,edgeId,edgeIntAccess)); |
94 | | -priorityEnc.setDecimal(false,edgeId,edgeIntAccess,PriorityCode.getValue(handlePriority(way,maxSpeed,priorityFromRelation))); |
95 | | - } |
96 | | - |
97 | | -/** |
98 | | - * In this method we prefer cycleways or roads with designated bike access and avoid big roads |
99 | | - * or roads with trams or pedestrian. |
100 | | - * |
101 | | - * @return new priority based on priorityFromRelation and on the tags in ReaderWay. |
102 | | - */ |
103 | | -inthandlePriority(ReaderWayway,doublewayTypeSpeed,IntegerpriorityFromRelation) { |
104 | 95 | TreeMap<Double,PriorityCode>weightToPrioMap =newTreeMap<>(); |
105 | 96 | if (priorityFromRelation ==null) |
106 | 97 | weightToPrioMap.put(0d,UNCHANGED); |
107 | 98 | else |
108 | | -weightToPrioMap.put(110d,PriorityCode.valueOf(priorityFromRelation)); |
| 99 | +weightToPrioMap.put(110d,priorityFromRelation); |
109 | 100 |
|
110 | | -collect(way,wayTypeSpeed,weightToPrioMap); |
| 101 | +doublemaxSpeed =Math.max(avgSpeedEnc.getDecimal(false,edgeId,edgeIntAccess), |
| 102 | +avgSpeedEnc.getDecimal(true,edgeId,edgeIntAccess)); |
| 103 | +collect(way,maxSpeed,RouteNetwork.MISSING !=bikeRouteNetwork ||isBikeDesignated(way),weightToPrioMap); |
111 | 104 |
|
112 | 105 | // pick priority with biggest order value |
113 | | -returnweightToPrioMap.lastEntry().getValue().getValue(); |
| 106 | +doubleprio =PriorityCode.getValue(weightToPrioMap.lastEntry().getValue().getValue()); |
| 107 | +priorityEnc.setDecimal(false,edgeId,edgeIntAccess,prio); |
114 | 108 | } |
115 | 109 |
|
116 | 110 | // Conversion of class value to priority. See http://wiki.openstreetmap.org/wiki/Class:bicycle |
@@ -144,9 +138,9 @@ private PriorityCode convertClassValueToPriority(String tagvalue) { |
144 | 138 | * @param weightToPrioMap associate a weight with every priority. This sorted map allows |
145 | 139 | * subclasses to 'insert' more important priorities as well as overwrite determined priorities. |
146 | 140 | */ |
147 | | -voidcollect(ReaderWayway,doublewayTypeSpeed,TreeMap<Double,PriorityCode>weightToPrioMap) { |
| 141 | +voidcollect(ReaderWayway,doublewayTypeSpeed,booleanbikeDesignated,TreeMap<Double,PriorityCode>weightToPrioMap) { |
148 | 142 | Stringhighway =way.getTag("highway"); |
149 | | -if (isDesignated(way)) { |
| 143 | +if (bikeDesignated) { |
150 | 144 | booleanisGoodSurface =way.getTag("tracktype","").equals("grade1") ||goodSurface.contains(way.getTag("surface","")); |
151 | 145 | if ("path".equals(highway) ||"track".equals(highway) &&isGoodSurface) |
152 | 146 | weightToPrioMap.put(100d,VERY_NICE); |
@@ -193,7 +187,7 @@ void collect(ReaderWay way, double wayTypeSpeed, TreeMap<Double, PriorityCode> w |
193 | 187 | pushingSectionPrio =BAD; |
194 | 188 | elseif (way.hasTag("bicycle","yes") ||way.hasTag("bicycle","permissive")) |
195 | 189 | pushingSectionPrio =PREFER; |
196 | | -elseif (isDesignated(way)) |
| 190 | +elseif (bikeDesignated) |
197 | 191 | pushingSectionPrio =VERY_NICE; |
198 | 192 |
|
199 | 193 | if (way.hasTag("foot","yes") && !way.hasTag("segregated","yes")) |
@@ -226,9 +220,14 @@ else if (isDesignated(way)) |
226 | 220 | } |
227 | 221 | } |
228 | 222 |
|
229 | | -booleanisDesignated(ReaderWayway) { |
230 | | -returnway.hasTag("bicycle","designated") ||way.hasTag(CYCLEWAY_BICYCLE_KEYS,"designated") |
231 | | - ||way.hasTag("bicycle_road","yes") ||way.hasTag("cyclestreet","yes") ||way.hasTag("bicycle","official"); |
| 223 | +staticbooleanisBikeDesignated(ReaderWayway) { |
| 224 | +returnway.hasTag("bicycle","designated") |
| 225 | + ||way.hasTag("bicycle","official") |
| 226 | + ||way.hasTag("segregated","yes") |
| 227 | + ||way.hasTag("bicycle_road","yes") |
| 228 | + ||way.hasTag("cyclestreet","yes") |
| 229 | + ||CYCLEWAY_KEYS.stream().anyMatch(k ->way.getTag(k,"").equals("track")) |
| 230 | + ||way.hasTag(CYCLEWAY_BICYCLE_KEYS,"designated"); |
232 | 231 | } |
233 | 232 |
|
234 | 233 | voidaddPushingSection(Stringhighway) { |
|