Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Releasing is documented in RELEASE.md
## [unreleased]

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

### Changed
- remove spurious entry for an unassigned country ID value 137 from the documentation ([#2103](https://github.com/GIScience/openrouteservice/pull/2103))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4073,7 +4073,7 @@ void testCustomProfileSurfaceType() {

JSONObject customModel = new JSONObject();
JSONObject priority = new JSONObject();
priority.put("if", "surface == PAVING_STONES");
priority.put("if", "ors_surface == PAVING_STONES");
priority.put("multiply_by", 0);
customModel.put("priority", new JSONArray().put(priority));
body.put("custom_model", customModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.graphhopper.config.CHProfile;
import com.graphhopper.config.LMProfile;
import com.graphhopper.config.Profile;
import com.graphhopper.routing.ev.Surface;
import com.graphhopper.routing.ev.OrsSurface;
import com.graphhopper.routing.weighting.custom.CustomProfile;
import com.graphhopper.util.CustomModel;
import com.graphhopper.util.Helper;
Expand Down Expand Up @@ -260,7 +260,7 @@ public static ORSGraphHopperConfig createGHSettings(ProfileProperties profile, E
}

private static void addGraphLevelEncodedValues(ORSGraphHopperConfig ghConfig) {
ghConfig.putObject("graph.encoded_values", Surface.KEY);
ghConfig.putObject("graph.encoded_values", OrsSurface.KEY);
}

public List<CHProfile> getCoreProfiles() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ public EncodedValue create(String encodedValueString) {
if (Helper.isEmpty(encodedValueString))
throw new IllegalArgumentException("No string provided to load EncodedValue");

final EncodedValue enc;
String name = encodedValueString.split("\\|")[0];
if (name.isEmpty())
throw new IllegalArgumentException("To load EncodedValue a name is required. " + encodedValueString);

if (DynamicData.KEY.equals(name)) {
enc = DynamicData.create();
} else {
// Fallback to GraphHopper's EncodedValues
enc = defaultEncodedValueFactory.create(encodedValueString);
}
return enc;
return switch (name) {
case DynamicData.KEY -> DynamicData.create();
default -> defaultEncodedValueFactory.create(encodedValueString); // Fallback to GraphHopper's EncodedValues
};
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.heigit.ors.routing.graphhopper.extensions;

import com.graphhopper.routing.ev.OrsSurface;
import com.graphhopper.routing.util.parsers.DefaultTagParserFactory;
import com.graphhopper.routing.util.parsers.TagParser;
import com.graphhopper.routing.util.parsers.TagParserFactory;
import com.graphhopper.util.PMap;
import org.heigit.ors.routing.graphhopper.extensions.util.parsers.OrsSurfaceParser;

public class OrsTagParserFactory implements TagParserFactory {
DefaultTagParserFactory defaultTagParserFactory = new DefaultTagParserFactory();
Expand All @@ -13,12 +15,10 @@ public TagParser create(String name, PMap configuration) {
try {
return defaultTagParserFactory.create(name, configuration);
} catch (IllegalArgumentException e) {
// TODO: add a new tag parser for each new encoded value here:
// return switch (name) {
// case MyNewEncodedValue.KEY -> new MyNewTagParserTagParser();
// default -> throw e;
// };
throw e;
return switch (name) {
case OrsSurface.KEY -> new OrsSurfaceParser();
default -> throw e;
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.heigit.ors.routing.graphhopper.extensions.util.parsers;

import com.graphhopper.reader.ReaderWay;
import com.graphhopper.routing.ev.*;
import com.graphhopper.routing.util.parsers.TagParser;
import com.graphhopper.storage.IntsRef;

import java.util.List;

public class OrsSurfaceParser implements TagParser {
private EnumEncodedValue<OrsSurface> surfaceEnc;

public OrsSurfaceParser() {
this(new EnumEncodedValue<>(OrsSurface.KEY, OrsSurface.class));
}

public OrsSurfaceParser(EnumEncodedValue<OrsSurface> surfaceEnc) {
this.surfaceEnc = surfaceEnc;
}

@Override
public void createEncodedValues(EncodedValueLookup encodedValueLookup, List<EncodedValue> list) {
list.add(surfaceEnc);
}

@Override
public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay readerWay, boolean b, IntsRef relationFlags) {
String surfaceTag = readerWay.getTag("surface");
OrsSurface surface = getFromString(surfaceTag);
surfaceEnc.setEnum(false, edgeFlags, surface);
return edgeFlags;
}

private static OrsSurface getFromString(String surface) {
if (surface == null)
return OrsSurface.UNKNOWN;

if (surface.contains(";"))
surface = surface.split(";")[0];
if (surface.contains(":"))
surface = surface.split(":")[0];

return switch (surface.toLowerCase()) {
case "paved" -> OrsSurface.PAVED;
case "unpaved", "woodchips", "rock", "rocks", "stone", "shells", "salt" -> OrsSurface.UNPAVED;
case "asphalt", "chipseal", "bitmac", "tarmac" -> OrsSurface.ASPHALT;
case "concrete", "cement" -> OrsSurface.CONCRETE;
case "paving_stones", "paved_stones", "sett", "cobblestone", "unhewn_cobblestone", "bricks", "brick" -> OrsSurface.PAVING_STONES;
case "metal" -> OrsSurface.METAL;
case "wood" -> OrsSurface.WOOD;
case "compacted", "pebblestone" -> OrsSurface.COMPACTED_GRAVEL;
case "gravel", "fine_gravel" -> OrsSurface.GRAVEL;
case "dirt", "earth", "soil" -> OrsSurface.DIRT;
case "ground", "mud" -> OrsSurface.GROUND;
case "ice", "snow" -> OrsSurface.ICE;
case "sand" -> OrsSurface.SAND;
case "grass" -> OrsSurface.GRASS;
case "grass_paver" -> OrsSurface.GRASS_PAVER;
default -> OrsSurface.UNKNOWN;
};
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'</maven.build.timestamp.format>

<!-- switch graphhopper versions to enable debugging -->
<graphhopper.version>v4.9.8</graphhopper.version>
<graphhopper.version>v4.9.9</graphhopper.version>
<!-- <graphhopper.version>4.9-SNAPSHOT</graphhopper.version>-->
<lombok.version>1.18.34</lombok.version>
<slf4j.version>2.0.13</slf4j.version>
Expand Down
Loading