Skip to content

Commit 44b4dc2

Browse files
author
Peter
committed
improving situation for sidewalk=no via WORST prio code, graphhopper#476
1 parent 29dc23a commit 44b4dc2

File tree

4 files changed

+43
-33
lines changed

4 files changed

+43
-33
lines changed

core/src/main/java/com/graphhopper/routing/util/FootFlagEncoder.java

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ public FootFlagEncoder( int speedBits, double speedFactor )
109109
avoidHighwayTags.add("trunk_link");
110110
avoidHighwayTags.add("primary");
111111
avoidHighwayTags.add("primary_link");
112-
avoidHighwayTags.add("tertiary");
113-
avoidHighwayTags.add("tertiary_link");
114112
// for now no explicit avoiding #257
115113
//avoidHighwayTags.add("cycleway");
116114

@@ -119,6 +117,8 @@ public FootFlagEncoder( int speedBits, double speedFactor )
119117
allowedHighwayTags.add("cycleway");
120118
allowedHighwayTags.add("secondary");
121119
allowedHighwayTags.add("secondary_link");
120+
allowedHighwayTags.add("tertiary");
121+
allowedHighwayTags.add("tertiary_link");
122122
allowedHighwayTags.add("unclassified");
123123
allowedHighwayTags.add("road");
124124
// disallowed in some countries
@@ -358,30 +358,24 @@ void collect( OSMWay way, TreeMap<Double, Integer> weightToPrioMap )
358358
{
359359
weightToPrioMap.put(40d, PREFER.getValue());
360360
if (way.hasTag("tunnel", intendedValues))
361-
weightToPrioMap.put(40d, UNCHANGED.getValue());
362-
}
363-
364-
if (way.hasTag("bicycle", "official") || way.hasTag("bicycle", "designated"))
365-
{
366-
weightToPrioMap.put(44d, AVOID_IF_POSSIBLE.getValue());
367-
}
368-
369-
if (avoidHighwayTags.contains(highway) || maxSpeed > 50)
370-
{
371-
if (way.hasTag("sidewalk", sidewalks))
372-
{
373-
weightToPrioMap.put(45d, REACH_DEST.getValue());
374-
} else
375361
{
376-
weightToPrioMap.put(45d, AVOID_AT_ALL_COSTS.getValue());
362+
if (way.hasTag("sidewalk", "no"))
363+
weightToPrioMap.put(40d, REACH_DEST.getValue());
364+
else
365+
weightToPrioMap.put(40d, UNCHANGED.getValue());
377366
}
378-
} else
367+
} else if (maxSpeed > 50 || avoidHighwayTags.contains(highway))
379368
{
380369
if (way.hasTag("sidewalk", sidewalks))
381-
{
382-
weightToPrioMap.put(45d, PREFER.getValue());
383-
}
370+
weightToPrioMap.put(45d, AVOID_IF_POSSIBLE.getValue());
371+
else if (way.hasTag("sidewalk", "no"))
372+
weightToPrioMap.put(45d, WORST.getValue());
373+
else
374+
weightToPrioMap.put(45d, REACH_DEST.getValue());
384375
}
376+
377+
if (way.hasTag("bicycle", "official") || way.hasTag("bicycle", "designated"))
378+
weightToPrioMap.put(44d, AVOID_IF_POSSIBLE.getValue());
385379
}
386380

387381
@Override

core/src/main/java/com/graphhopper/routing/util/PriorityCode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public enum PriorityCode
2929
AVOID_AT_ALL_COSTS(1),
3030
REACH_DEST(2),
3131
AVOID_IF_POSSIBLE(3),
32-
UNCHANGED(4),
33-
PREFER(5),
34-
VERY_NICE(6),
32+
UNCHANGED(5),
33+
PREFER(6),
34+
VERY_NICE(7),
3535
BEST(7);
3636
private final int value;
3737

core/src/test/java/com/graphhopper/routing/util/FootFlagEncoderTest.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,25 +203,41 @@ public void testPriority()
203203
assertEquals(PriorityCode.UNCHANGED.getValue(), footEncoder.handlePriority(way, 0));
204204

205205
way.setTag("highway", "primary");
206-
assertEquals(PriorityCode.AVOID_AT_ALL_COSTS.getValue(), footEncoder.handlePriority(way, 0));
207-
206+
assertEquals(PriorityCode.REACH_DEST.getValue(), footEncoder.handlePriority(way, 0));
207+
208208
way.setTag("highway", "track");
209209
way.setTag("bicycle", "official");
210210
assertEquals(PriorityCode.AVOID_IF_POSSIBLE.getValue(), footEncoder.handlePriority(way, 0));
211211

212212
way.setTag("highway", "track");
213213
way.setTag("bicycle", "designated");
214214
assertEquals(PriorityCode.AVOID_IF_POSSIBLE.getValue(), footEncoder.handlePriority(way, 0));
215-
215+
216216
way.setTag("highway", "cycleway");
217217
way.setTag("bicycle", "designated");
218-
way.setTag("foot", "designated");
218+
way.setTag("foot", "designated");
219219
assertEquals(PriorityCode.PREFER.getValue(), footEncoder.handlePriority(way, 0));
220-
220+
221221
way.clearTags();
222222
way.setTag("highway", "primary");
223223
way.setTag("sidewalk", "yes");
224-
assertEquals(PriorityCode.REACH_DEST.getValue(), footEncoder.handlePriority(way, 0));
224+
assertEquals(PriorityCode.AVOID_IF_POSSIBLE.getValue(), footEncoder.handlePriority(way, 0));
225+
226+
way.clearTags();
227+
way.setTag("highway", "cycleway");
228+
way.setTag("sidewalk", "no");
229+
assertEquals(PriorityCode.UNCHANGED.getValue(), footEncoder.handlePriority(way, 0));
230+
231+
way.clearTags();
232+
way.setTag("highway", "road");
233+
way.setTag("bicycle", "official");
234+
way.setTag("sidewalk", "no");
235+
assertEquals(PriorityCode.AVOID_IF_POSSIBLE.getValue(), footEncoder.handlePriority(way, 0));
236+
237+
way.clearTags();
238+
way.setTag("highway", "residential");
239+
way.setTag("sidewalk", "yes");
240+
assertEquals(PriorityCode.PREFER.getValue(), footEncoder.handlePriority(way, 0));
225241
}
226242

227243
@Test

web/nbactions.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
2929
</goals>
3030
<properties>
31-
<exec.args>-classpath %classpath com.graphhopper.http.GHServer graph.elevation.cachedir=../srtmprovider jetty.port=8989 config=../config.properties osmreader.osm=../europe_germany_berlin.pbf</exec.args>
31+
<exec.args>-classpath %classpath com.graphhopper.http.GHServer jetty.port=8989 config=../config.properties osmreader.osm=/home/peterk/Downloads/map.osm</exec.args>
3232
<exec.executable>java</exec.executable>
3333
</properties>
3434
</action>
@@ -42,7 +42,7 @@
4242
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
4343
</goals>
4444
<properties>
45-
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath com.graphhopper.http.GHServer graph.elevation.cachedir=../srtmprovider jetty.port=8989 config=../config.properties osmreader.osm=../europe_germany_berlin.pbf</exec.args>
45+
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath com.graphhopper.http.GHServer jetty.port=8989 config=../config.properties osmreader.osm=/home/peterk/Downloads/map.osm</exec.args>
4646
<exec.executable>java</exec.executable>
4747
<jpda.listen>true</jpda.listen>
4848
</properties>
@@ -57,7 +57,7 @@
5757
<goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
5858
</goals>
5959
<properties>
60-
<exec.args>-classpath %classpath com.graphhopper.http.GHServer graph.elevation.cachedir=../srtmprovider jetty.port=8989 config=../config.properties osmreader.osm=../europe_germany_berlin.pbf</exec.args>
60+
<exec.args>-classpath %classpath com.graphhopper.http.GHServer jetty.port=8989 config=../config.properties osmreader.osm=/home/peterk/Downloads/map.osm</exec.args>
6161
<exec.executable>java</exec.executable>
6262
</properties>
6363
</action>

0 commit comments

Comments
 (0)