Skip to content

Commit 957c6ac

Browse files
authored
feat: enable ors surface ev (#2110)
2 parents d283114 + 0adfac8 commit 957c6ac

File tree

6 files changed

+74
-11
lines changed

6 files changed

+74
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ Releasing is documented in RELEASE.md
2828
## [unreleased]
2929

3030
### Added
31-
- Full support for EncodedValues ([#2106](https://github.com/GIScience/openrouteservice/issues/2106))
31+
- full support for encoded values ([#2108](https://github.com/GIScience/openrouteservice/issues/2108))
32+
- enable encoded value "ors_surface" ([#2110](https://github.com/GIScience/openrouteservice/issues/2110))
3233

3334
### Changed
3435
- remove spurious entry for an unassigned country ID value 137 from the documentation ([#2103](https://github.com/GIScience/openrouteservice/pull/2103))

ors-api/src/test/java/org/heigit/ors/apitests/routing/ResultTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4073,7 +4073,7 @@ void testCustomProfileSurfaceType() {
40734073

40744074
JSONObject customModel = new JSONObject();
40754075
JSONObject priority = new JSONObject();
4076-
priority.put("if", "surface == PAVING_STONES");
4076+
priority.put("if", "ors_surface == PAVING_STONES");
40774077
priority.put("multiply_by", 0);
40784078
customModel.put("priority", new JSONArray().put(priority));
40794079
body.put("custom_model", customModel);

ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/ORSGraphHopperConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.graphhopper.config.CHProfile;
55
import com.graphhopper.config.LMProfile;
66
import com.graphhopper.config.Profile;
7-
import com.graphhopper.routing.ev.Surface;
7+
import com.graphhopper.routing.ev.OrsSurface;
88
import com.graphhopper.routing.weighting.custom.CustomProfile;
99
import com.graphhopper.util.CustomModel;
1010
import com.graphhopper.util.Helper;
@@ -260,7 +260,7 @@ public static ORSGraphHopperConfig createGHSettings(ProfileProperties profile, E
260260
}
261261

262262
private static void addGraphLevelEncodedValues(ORSGraphHopperConfig ghConfig) {
263-
ghConfig.putObject("graph.encoded_values", Surface.KEY);
263+
ghConfig.putObject("graph.encoded_values", OrsSurface.KEY);
264264
}
265265

266266
public List<CHProfile> getCoreProfiles() {
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package org.heigit.ors.routing.graphhopper.extensions;
22

3+
import com.graphhopper.routing.ev.OrsSurface;
34
import com.graphhopper.routing.util.parsers.DefaultTagParserFactory;
45
import com.graphhopper.routing.util.parsers.TagParser;
56
import com.graphhopper.routing.util.parsers.TagParserFactory;
67
import com.graphhopper.util.PMap;
8+
import org.heigit.ors.routing.graphhopper.extensions.util.parsers.OrsSurfaceParser;
79

810
public class OrsTagParserFactory implements TagParserFactory {
911
DefaultTagParserFactory defaultTagParserFactory = new DefaultTagParserFactory();
@@ -13,12 +15,10 @@ public TagParser create(String name, PMap configuration) {
1315
try {
1416
return defaultTagParserFactory.create(name, configuration);
1517
} catch (IllegalArgumentException e) {
16-
// TODO: add a new tag parser for each new encoded value here:
17-
// return switch (name) {
18-
// case MyNewEncodedValue.KEY -> new MyNewTagParserTagParser();
19-
// default -> throw e;
20-
// };
21-
throw e;
18+
return switch (name) {
19+
case OrsSurface.KEY -> new OrsSurfaceParser();
20+
default -> throw e;
21+
};
2222
}
2323
}
2424
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package org.heigit.ors.routing.graphhopper.extensions.util.parsers;
2+
3+
import com.graphhopper.reader.ReaderWay;
4+
import com.graphhopper.routing.ev.*;
5+
import com.graphhopper.routing.util.parsers.TagParser;
6+
import com.graphhopper.storage.IntsRef;
7+
8+
import java.util.List;
9+
10+
public class OrsSurfaceParser implements TagParser {
11+
private EnumEncodedValue<OrsSurface> surfaceEnc;
12+
13+
public OrsSurfaceParser() {
14+
this(new EnumEncodedValue<>(OrsSurface.KEY, OrsSurface.class));
15+
}
16+
17+
public OrsSurfaceParser(EnumEncodedValue<OrsSurface> surfaceEnc) {
18+
this.surfaceEnc = surfaceEnc;
19+
}
20+
21+
@Override
22+
public void createEncodedValues(EncodedValueLookup encodedValueLookup, List<EncodedValue> list) {
23+
list.add(surfaceEnc);
24+
}
25+
26+
@Override
27+
public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay readerWay, boolean b, IntsRef relationFlags) {
28+
String surfaceTag = readerWay.getTag("surface");
29+
OrsSurface surface = getFromString(surfaceTag);
30+
surfaceEnc.setEnum(false, edgeFlags, surface);
31+
return edgeFlags;
32+
}
33+
34+
private static OrsSurface getFromString(String surface) {
35+
if (surface == null)
36+
return OrsSurface.UNKNOWN;
37+
38+
if (surface.contains(";"))
39+
surface = surface.split(";")[0];
40+
if (surface.contains(":"))
41+
surface = surface.split(":")[0];
42+
43+
return switch (surface.toLowerCase()) {
44+
case "paved" -> OrsSurface.PAVED;
45+
case "unpaved", "woodchips", "rock", "rocks", "stone", "shells", "salt" -> OrsSurface.UNPAVED;
46+
case "asphalt", "chipseal", "bitmac", "tarmac" -> OrsSurface.ASPHALT;
47+
case "concrete", "cement" -> OrsSurface.CONCRETE;
48+
case "paving_stones", "paved_stones", "sett", "cobblestone", "unhewn_cobblestone", "bricks", "brick" -> OrsSurface.PAVING_STONES;
49+
case "metal" -> OrsSurface.METAL;
50+
case "wood" -> OrsSurface.WOOD;
51+
case "compacted", "pebblestone" -> OrsSurface.COMPACTED_GRAVEL;
52+
case "gravel", "fine_gravel" -> OrsSurface.GRAVEL;
53+
case "dirt", "earth", "soil" -> OrsSurface.DIRT;
54+
case "ground", "mud" -> OrsSurface.GROUND;
55+
case "ice", "snow" -> OrsSurface.ICE;
56+
case "sand" -> OrsSurface.SAND;
57+
case "grass" -> OrsSurface.GRASS;
58+
case "grass_paver" -> OrsSurface.GRASS_PAVER;
59+
default -> OrsSurface.UNKNOWN;
60+
};
61+
}
62+
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'</maven.build.timestamp.format>
4646

4747
<!-- switch graphhopper versions to enable debugging -->
48-
<graphhopper.version>v4.9.8</graphhopper.version>
48+
<graphhopper.version>v4.9.9</graphhopper.version>
4949
<!-- <graphhopper.version>4.9-SNAPSHOT</graphhopper.version>-->
5050
<lombok.version>1.18.34</lombok.version>
5151
<slf4j.version>2.0.13</slf4j.version>

0 commit comments

Comments
 (0)