Skip to content

Commit c4ccf9d

Browse files
committed
increase priority on avoided highways if there is bike network
1 parent 4001f71 commit c4ccf9d

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

core/src/main/java/com/graphhopper/reader/osm/OSMReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ private double calcDistance(ReaderWay way, WaySegmentParser.CoordinateSupplier c
567567
* This method is called for each relation during the first pass of {@link WaySegmentParser}
568568
*/
569569
protected void preprocessRelations(ReaderRelation relation) {
570-
if (!relation.isMetaRelation() && relation.hasTag("type", "route")) {
570+
if (relation.hasTag("type", "route")) {
571571
// we keep track of all route relations, so they are available when we create edges later
572572
for (ReaderRelation.Member member : relation.getMembers()) {
573573
if (member.getType() != ReaderElement.Type.WAY)

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import static com.graphhopper.routing.util.parsers.AbstractAccessParser.INTENDED;
1616

1717
public abstract class BikeCommonPriorityParser implements TagParser {
18-
1918
// Bicycle tracks subject to compulsory use in Germany and Poland (https://wiki.openstreetmap.org/wiki/DE:Key:cycleway)
2019
private static final List<String> CYCLEWAY_BICYCLE_KEYS = List.of("cycleway:bicycle", "cycleway:both:bicycle", "cycleway:left:bicycle", "cycleway:right:bicycle");
2120

@@ -85,6 +84,7 @@ protected BikeCommonPriorityParser(DecimalEncodedValue priorityEnc, DecimalEncod
8584
public void handleWayTags(int edgeId, EdgeIntAccess edgeIntAccess, ReaderWay way, IntsRef relationFlags) {
8685
String highwayValue = way.getTag("highway");
8786
Integer priorityFromRelation = routeMap.get(bikeRouteEnc.getEnum(false, edgeId, edgeIntAccess));
87+
RouteNetwork bikeNetork = this.bikeRouteEnc.getEnum(false, edgeId, edgeIntAccess);
8888
if (highwayValue == null) {
8989
if (FerrySpeedCalculator.isFerry(way)) {
9090
priorityFromRelation = SLIGHT_AVOID.getValue();
@@ -94,7 +94,7 @@ public void handleWayTags(int edgeId, EdgeIntAccess edgeIntAccess, ReaderWay way
9494
}
9595

9696
double maxSpeed = Math.max(avgSpeedEnc.getDecimal(false, edgeId, edgeIntAccess), avgSpeedEnc.getDecimal(true, edgeId, edgeIntAccess));
97-
priorityEnc.setDecimal(false, edgeId, edgeIntAccess, PriorityCode.getValue(handlePriority(way, maxSpeed, priorityFromRelation)));
97+
priorityEnc.setDecimal(false, edgeId, edgeIntAccess, PriorityCode.getValue(handlePriority(way, maxSpeed, priorityFromRelation, bikeNetork)));
9898
}
9999

100100
/**
@@ -103,14 +103,14 @@ public void handleWayTags(int edgeId, EdgeIntAccess edgeIntAccess, ReaderWay way
103103
*
104104
* @return new priority based on priorityFromRelation and on the tags in ReaderWay.
105105
*/
106-
int handlePriority(ReaderWay way, double wayTypeSpeed, Integer priorityFromRelation) {
106+
int handlePriority(ReaderWay way, double wayTypeSpeed, Integer priorityFromRelation, RouteNetwork bikeNetork) {
107107
TreeMap<Double, PriorityCode> weightToPrioMap = new TreeMap<>();
108108
if (priorityFromRelation == null)
109109
weightToPrioMap.put(0d, UNCHANGED);
110110
else
111111
weightToPrioMap.put(110d, PriorityCode.valueOf(priorityFromRelation));
112112

113-
collect(way, wayTypeSpeed, weightToPrioMap);
113+
collect(way, wayTypeSpeed, weightToPrioMap, bikeNetork);
114114

115115
// pick priority with biggest order value
116116
return weightToPrioMap.lastEntry().getValue().getValue();
@@ -147,8 +147,9 @@ private PriorityCode convertClassValueToPriority(String tagvalue) {
147147
* @param weightToPrioMap associate a weight with every priority. This sorted map allows
148148
* subclasses to 'insert' more important priorities as well as overwrite determined priorities.
149149
*/
150-
void collect(ReaderWay way, double wayTypeSpeed, TreeMap<Double, PriorityCode> weightToPrioMap) {
150+
void collect(ReaderWay way, double wayTypeSpeed, TreeMap<Double, PriorityCode> weightToPrioMap, RouteNetwork bikeNetork) {
151151
String highway = way.getTag("highway");
152+
152153
if (isDesignated(way)) {
153154
boolean isGoodSurface = way.getTag("tracktype", "").equals("grade1") || goodSurface.contains(way.getTag("surface",""));
154155
if ("path".equals(highway) || "track".equals(highway) && isGoodSurface)
@@ -174,7 +175,15 @@ void collect(ReaderWay way, double wayTypeSpeed, TreeMap<Double, PriorityCode> w
174175
} else if (avoidHighwayTags.containsKey(highway)
175176
|| (maxSpeed != MaxSpeed.MAXSPEED_MISSING && maxSpeed >= avoidSpeedLimit && !"track".equals(highway))) {
176177
PriorityCode priorityCode = avoidHighwayTags.get(highway);
177-
weightToPrioMap.put(50d, priorityCode == null ? AVOID : priorityCode);
178+
179+
180+
if (bikeNetork != RouteNetwork.MISSING) {
181+
// If there's a bike network on an avoided highway, give it a better priority than REACH_DESTINATION
182+
weightToPrioMap.put(50d, AVOID);
183+
} else {
184+
weightToPrioMap.put(50d, priorityCode == null ? AVOID : priorityCode);
185+
}
186+
178187
if (way.hasTag("tunnel", INTENDED)) {
179188
PriorityCode worse = priorityCode == null ? BAD : priorityCode.worse().worse();
180189
weightToPrioMap.put(50d, worse == EXCLUDE ? REACH_DESTINATION : worse);

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
@@ -39,8 +39,8 @@ protected MountainBikePriorityParser(DecimalEncodedValue speedEnc, DecimalEncode
3939
}
4040

4141
@Override
42-
void collect(ReaderWay way, double wayTypeSpeed, TreeMap<Double, PriorityCode> weightToPrioMap) {
43-
super.collect(way, wayTypeSpeed, weightToPrioMap);
42+
void collect(ReaderWay way, double wayTypeSpeed, TreeMap<Double, PriorityCode> weightToPrioMap, RouteNetwork bikeNetork) {
43+
super.collect(way, wayTypeSpeed, weightToPrioMap, bikeNetork);
4444

4545
String highway = way.getTag("highway");
4646
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
@@ -48,8 +48,8 @@ protected RacingBikePriorityParser(DecimalEncodedValue priorityEnc, DecimalEncod
4848
}
4949

5050
@Override
51-
void collect(ReaderWay way, double wayTypeSpeed, TreeMap<Double, PriorityCode> weightToPrioMap) {
52-
super.collect(way, wayTypeSpeed, weightToPrioMap);
51+
void collect(ReaderWay way, double wayTypeSpeed, TreeMap<Double, PriorityCode> weightToPrioMap, RouteNetwork bikeNetork) {
52+
super.collect(way, wayTypeSpeed, weightToPrioMap, bikeNetork);
5353

5454
String highway = way.getTag("highway");
5555
if ("service".equals(highway) || "residential".equals(highway)) {

0 commit comments

Comments
 (0)