Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2c8f2c8

Browse files
committed
bike parser clean up
1 parent4f49711 commit2c8f2c8

File tree

4 files changed

+33
-43
lines changed

4 files changed

+33
-43
lines changed

‎core/src/main/java/com/graphhopper/routing/util/parsers/BikeCommonAverageSpeedParser.java‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
importcom.graphhopper.reader.ReaderWay;
44
importcom.graphhopper.routing.ev.*;
55
importcom.graphhopper.routing.util.FerrySpeedCalculator;
6-
importcom.graphhopper.storage.IntsRef;
76

87
importjava.util.Arrays;
98
importjava.util.HashMap;
@@ -14,7 +13,6 @@
1413

1514
publicabstractclassBikeCommonAverageSpeedParserextendsAbstractAverageSpeedParserimplementsTagParser {
1615

17-
privatestaticfinalSet<String>CYCLEWAY_KEYS =Set.of("cycleway","cycleway:left","cycleway:both","cycleway:right");
1816
protectedstaticfinalintPUSHING_SECTION_SPEED =4;
1917
protectedstaticfinalintMIN_SPEED =2;
2018
privatefinalMap<String,Integer>trackTypeSpeeds =newHashMap<>();
@@ -120,12 +118,8 @@ protected BikeCommonAverageSpeedParser(DecimalEncodedValue speedEnc,
120118
returnMath.min(speed,maxSpeed);
121119
}
122120

123-
publicvoidhandleWayTags(intedgeId,EdgeIntAccessedgeIntAccess,ReaderWayway) {
124-
thrownewIllegalArgumentException("use handleWayTags with relationFlags");
125-
}
126-
127121
@Override
128-
publicvoidhandleWayTags(intedgeId,EdgeIntAccessedgeIntAccess,ReaderWayway,IntsRefrelationFlags) {
122+
publicvoidhandleWayTags(intedgeId,EdgeIntAccessedgeIntAccess,ReaderWayway) {
129123
StringhighwayValue =way.getTag("highway","");
130124
if (highwayValue.isEmpty()) {
131125
if (FerrySpeedCalculator.isFerry(way)) {
@@ -146,11 +140,8 @@ public void handleWayTags(int edgeId, EdgeIntAccess edgeIntAccess, ReaderWay way
146140
IntegertrackTypeSpeed =trackTypeSpeeds.get(trackTypeValue);
147141
if (trackTypeSpeed !=null)
148142
surfaceSpeed =surfaceSpeed ==null ?trackTypeSpeed :Math.min(surfaceSpeed,trackTypeSpeed);
149-
booleanbikeDesignated =way.hasTag("bicycle","designated")
150-
||way.hasTag("bicycle","official")
151-
||way.hasTag("segregated","yes")
152-
||CYCLEWAY_KEYS.stream().anyMatch(k ->way.getTag(k,"").equals("track"))
153-
||RouteNetwork.MISSING !=bikeRouteEnc.getEnum(false,edgeId,edgeIntAccess);
143+
booleanbikeDesignated =RouteNetwork.MISSING !=bikeRouteEnc.getEnum(false,edgeId,edgeIntAccess)
144+
||BikeCommonPriorityParser.isBikeDesignated(way);
154145

155146
if (way.hasTag("surface") &&surfaceSpeed ==null
156147
||way.hasTag("bicycle","dismount")

‎core/src/main/java/com/graphhopper/routing/util/parsers/BikeCommonPriorityParser.java‎

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
importstaticcom.graphhopper.routing.util.parsers.AbstractAccessParser.INTENDED;
1515

1616
publicabstractclassBikeCommonPriorityParserimplementsTagParser {
17+
privatestaticfinalSet<String>CYCLEWAY_KEYS =Set.of("cycleway","cycleway:left","cycleway:both","cycleway:right");
1718

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
1920
privatestaticfinalList<String>CYCLEWAY_BICYCLE_KEYS =List.of("cycleway:bicycle","cycleway:both:bicycle","cycleway:left:bicycle","cycleway:right:bicycle");
2021

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
2223
protectedfinalHashSet<String>pushingSectionsHighways =newHashSet<>();
2324
protectedfinalSet<String>preferHighwayTags =newHashSet<>();
2425
protectedfinalMap<String,PriorityCode>avoidHighwayTags =newHashMap<>();
@@ -76,41 +77,34 @@ protected BikeCommonPriorityParser(DecimalEncodedValue priorityEnc, DecimalEncod
7677
@Override
7778
publicvoidhandleWayTags(intedgeId,EdgeIntAccessedgeIntAccess,ReaderWayway,IntsRefrelationFlags) {
7879
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;
8385
}
8486

8587
if (highwayValue ==null) {
8688
if (FerrySpeedCalculator.isFerry(way)) {
87-
priorityFromRelation =SLIGHT_AVOID.getValue();
89+
priorityFromRelation =SLIGHT_AVOID;
8890
}else {
8991
return;
9092
}
9193
}
9294

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) {
10495
TreeMap<Double,PriorityCode>weightToPrioMap =newTreeMap<>();
10596
if (priorityFromRelation ==null)
10697
weightToPrioMap.put(0d,UNCHANGED);
10798
else
108-
weightToPrioMap.put(110d,PriorityCode.valueOf(priorityFromRelation));
99+
weightToPrioMap.put(110d,priorityFromRelation);
109100

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);
111104

112105
// 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);
114108
}
115109

116110
// Conversion of class value to priority. See http://wiki.openstreetmap.org/wiki/Class:bicycle
@@ -144,9 +138,9 @@ private PriorityCode convertClassValueToPriority(String tagvalue) {
144138
* @param weightToPrioMap associate a weight with every priority. This sorted map allows
145139
* subclasses to 'insert' more important priorities as well as overwrite determined priorities.
146140
*/
147-
voidcollect(ReaderWayway,doublewayTypeSpeed,TreeMap<Double,PriorityCode>weightToPrioMap) {
141+
voidcollect(ReaderWayway,doublewayTypeSpeed,booleanbikeDesignated,TreeMap<Double,PriorityCode>weightToPrioMap) {
148142
Stringhighway =way.getTag("highway");
149-
if (isDesignated(way)) {
143+
if (bikeDesignated) {
150144
booleanisGoodSurface =way.getTag("tracktype","").equals("grade1") ||goodSurface.contains(way.getTag("surface",""));
151145
if ("path".equals(highway) ||"track".equals(highway) &&isGoodSurface)
152146
weightToPrioMap.put(100d,VERY_NICE);
@@ -193,7 +187,7 @@ void collect(ReaderWay way, double wayTypeSpeed, TreeMap<Double, PriorityCode> w
193187
pushingSectionPrio =BAD;
194188
elseif (way.hasTag("bicycle","yes") ||way.hasTag("bicycle","permissive"))
195189
pushingSectionPrio =PREFER;
196-
elseif (isDesignated(way))
190+
elseif (bikeDesignated)
197191
pushingSectionPrio =VERY_NICE;
198192

199193
if (way.hasTag("foot","yes") && !way.hasTag("segregated","yes"))
@@ -226,9 +220,14 @@ else if (isDesignated(way))
226220
}
227221
}
228222

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");
232231
}
233232

234233
voidaddPushingSection(Stringhighway) {

‎core/src/main/java/com/graphhopper/routing/util/parsers/MountainBikePriorityParser.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ protected MountainBikePriorityParser(DecimalEncodedValue speedEnc, DecimalEncode
3434
}
3535

3636
@Override
37-
voidcollect(ReaderWayway,doublewayTypeSpeed,TreeMap<Double,PriorityCode>weightToPrioMap) {
38-
super.collect(way,wayTypeSpeed,weightToPrioMap);
37+
voidcollect(ReaderWayway,doublewayTypeSpeed,booleanbikeDesignated,TreeMap<Double,PriorityCode>weightToPrioMap) {
38+
super.collect(way,wayTypeSpeed,bikeDesignated,weightToPrioMap);
3939

4040
Stringhighway =way.getTag("highway");
4141
if ("track".equals(highway)) {

‎core/src/main/java/com/graphhopper/routing/util/parsers/RacingBikePriorityParser.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ protected RacingBikePriorityParser(DecimalEncodedValue priorityEnc, DecimalEncod
4343
}
4444

4545
@Override
46-
voidcollect(ReaderWayway,doublewayTypeSpeed,TreeMap<Double,PriorityCode>weightToPrioMap) {
47-
super.collect(way,wayTypeSpeed,weightToPrioMap);
46+
voidcollect(ReaderWayway,doublewayTypeSpeed,booleanbikeDesignated,TreeMap<Double,PriorityCode>weightToPrioMap) {
47+
super.collect(way,wayTypeSpeed,bikeDesignated,weightToPrioMap);
4848

4949
Stringhighway =way.getTag("highway");
5050
if ("service".equals(highway) ||"residential".equals(highway)) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp