diff --git a/core/src/main/java/com/graphhopper/reader/osm/OSMReader.java b/core/src/main/java/com/graphhopper/reader/osm/OSMReader.java index 04a1f93687a..635c2815187 100644 --- a/core/src/main/java/com/graphhopper/reader/osm/OSMReader.java +++ b/core/src/main/java/com/graphhopper/reader/osm/OSMReader.java @@ -328,7 +328,9 @@ protected void addEdge(int fromIndex, int toIndex, PointList pointList, ReaderWa throw new IllegalStateException("unaccepted way: " + way.getId()); IntsRef relationFlags = getRelFlagsMap(way.getId()); - IntsRef edgeFlags = encodingManager.handleWayTags(way, acceptWay, relationFlags); + // ORS-GH MOD START additional parameters for from and to node ids + IntsRef edgeFlags = encodingManager.handleWayTags(fromIndex, toIndex, way, acceptWay, relationFlags); + // ORS-GH MOD END if (edgeFlags.isEmpty()) return; diff --git a/core/src/main/java/com/graphhopper/reader/osm/WaySegmentParser.java b/core/src/main/java/com/graphhopper/reader/osm/WaySegmentParser.java index 37464bce2f5..b6a2fa9bdc6 100644 --- a/core/src/main/java/com/graphhopper/reader/osm/WaySegmentParser.java +++ b/core/src/main/java/com/graphhopper/reader/osm/WaySegmentParser.java @@ -265,8 +265,13 @@ public void handleWay(ReaderWay way) { // ORS-GH MOD START - way preprocessor might have changed the way tags, so we need to check the filter again if (!wayFilter.test(way)) return; + try { + splitWayAtJunctionsAndEmptySections(segment, way); + } catch (Exception e) { + LOGGER.error("Error while processing way " + way.getId() + ": " + e.getMessage()); + throw e; + } // ORS-GH MOD END - splitWayAtJunctionsAndEmptySections(segment, way); } private void splitWayAtJunctionsAndEmptySections(List fullSegment, ReaderWay way) { diff --git a/core/src/main/java/com/graphhopper/routing/ev/Country.java b/core/src/main/java/com/graphhopper/routing/ev/Country.java index 0569995f858..352daf7ed49 100644 --- a/core/src/main/java/com/graphhopper/routing/ev/Country.java +++ b/core/src/main/java/com/graphhopper/routing/ev/Country.java @@ -240,7 +240,14 @@ public enum Country { YEM("Yemen", "YE"), ZAF("South Africa", "ZA"), ZMB("Zambia", "ZM"), - ZWE("Zimbabwe", "ZW"); + // ORS-GH MOD START additional ORS-specific territories + ZWE("Zimbabwe", "ZW"), + // the following values are for testing purposes only + XXA("Area 1", "XA"), + XXB("Area 2", "XB"), + XXC("Area 3", "XC"), + XXD("Area 4", "XD"); + // ORS-GH MOD END public static final String KEY = "country"; diff --git a/core/src/main/java/com/graphhopper/routing/util/EncodingManager.java b/core/src/main/java/com/graphhopper/routing/util/EncodingManager.java index 8593fd2b470..8a9321a61ad 100644 --- a/core/src/main/java/com/graphhopper/routing/util/EncodingManager.java +++ b/core/src/main/java/com/graphhopper/routing/util/EncodingManager.java @@ -599,7 +599,17 @@ public void handleTurnRelationTags(OSMTurnRelation turnRelation, TurnCostParser. * @param relationFlags The preprocessed relation flags is used to influence the way properties. */ public IntsRef handleWayTags(ReaderWay way, AcceptWay acceptWay, IntsRef relationFlags) { + // ORS-GH MOD START additional parameters to provide from/to node ids to tag parsers + return handleWayTags(-1, -1, way, acceptWay, relationFlags); + } + + public IntsRef handleWayTags(int fromIndex, int toIndex, ReaderWay way, AcceptWay acceptWay, IntsRef relationFlags) { IntsRef edgeFlags = createEdgeFlags(); + // modified handler must be called before regular processing to ensure that "ors:country" tags set by the BorderParser are available for the downstream CountryParser + for (TagParser parser : edgeTagParsers) { + parser.handleWayTags(fromIndex, toIndex, edgeFlags, way, acceptWay.isFerry(), relationFlags); + } + // ORS-GH MOD END for (TagParser parser : edgeTagParsers) { parser.handleWayTags(edgeFlags, way, acceptWay.isFerry(), relationFlags); } diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/CountryParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/CountryParser.java index 999a7ea92e3..648cf7ca354 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/CountryParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/CountryParser.java @@ -28,6 +28,9 @@ public class CountryParser implements TagParser { private final EnumEncodedValue countryEnc; + // ORS-GH MOD START + public static final String KEY_ORS_COUNTRY = "ors:country"; + // ORS-GH MOD END public CountryParser() { this.countryEnc = Country.create(); @@ -41,6 +44,10 @@ public void createEncodedValues(EncodedValueLookup lookup, List re @Override public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay way, boolean ferry, IntsRef relationFlags) { Country country = way.getTag("country", Country.MISSING); + // ORS-GH MOD START override with country information set by ORS + if (way.hasTag(KEY_ORS_COUNTRY)) + country = way.getTag(KEY_ORS_COUNTRY, Country.MISSING); + // ORS-GH MOD END countryEnc.setEnum(false, edgeFlags, country); return edgeFlags; } diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/TagParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/TagParser.java index be49a8e2806..ea805eadde4 100644 --- a/core/src/main/java/com/graphhopper/routing/util/parsers/TagParser.java +++ b/core/src/main/java/com/graphhopper/routing/util/parsers/TagParser.java @@ -33,4 +33,10 @@ public interface TagParser { void createEncodedValues(EncodedValueLookup lookup, List registerNewEncodedValue); IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay way, boolean ferry, IntsRef relationFlags); + + // ORS-GH MOD START additional method to provide from/to node ids + default IntsRef handleWayTags(int from, int to, IntsRef edgeFlags, ReaderWay way, boolean ferry, IntsRef relationFlags) { + return edgeFlags; + } + // ORS-GH MOD END }