Skip to content

Commit 9e7ea22

Browse files
committed
feat: set "ors:country" way tags
1 parent df0ee3e commit 9e7ea22

5 files changed

Lines changed: 29 additions & 2 deletions

File tree

ors-engine/src/main/java/org/heigit/ors/config/profile/BuildProperties.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ private void handleTrailDifficulty() {
233233
}
234234

235235
private void handleBorder() {
236+
if (encodedValues.getCountry() == null) {
237+
encodedValues.setCountry(true);
238+
}
236239
if (encodedValues.getBorder() == null) {
237240
encodedValues.setBorder(true);
238241
}

ors-engine/src/main/java/org/heigit/ors/config/profile/EncodedValuesProperties.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public class EncodedValuesProperties {
6767
private Boolean mtbScale;
6868
@JsonProperty(MtbScaleUphill.KEY)
6969
private Boolean mtbScaleUphill;
70+
@JsonProperty(Country.KEY)
71+
private Boolean country;
7072
@JsonProperty(Border.KEY)
7173
private Boolean border;
7274

@@ -105,6 +107,7 @@ private Map<String, Boolean> getProperties() {
105107
properties.put(SacScale.KEY, sacScale);
106108
properties.put(MtbScale.KEY, mtbScale);
107109
properties.put(MtbScaleUphill.KEY, mtbScaleUphill);
110+
properties.put(Country.KEY, country);
108111
properties.put(Border.KEY, border);
109112

110113
return properties;
@@ -148,6 +151,7 @@ public void merge(EncodedValuesProperties other) {
148151
sacScale = ofNullable(this.sacScale).orElse(other.sacScale);
149152
mtbScale = ofNullable(this.mtbScale).orElse(other.mtbScale);
150153
mtbScaleUphill = ofNullable(this.mtbScaleUphill).orElse(other.mtbScaleUphill);
154+
country = ofNullable(this.country).orElse(other.country);
151155
border = ofNullable(this.border).orElse(other.border);
152156
}
153157
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,6 @@ protected void setArtificialWayTags(PointList pointList, ReaderWay way) {
421421
if (hillIndexCalculator != null) {
422422
calculateHillIndex(pointList, way);
423423
}
424-
425-
//TODO: set country "ors:country" tags before calling CountryParser
426424
}
427425

428426
private void calculateHillIndex(PointList pointList, ReaderWay way) {

ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/reader/borders/CountryBordersReader.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
package org.heigit.ors.routing.graphhopper.extensions.reader.borders;
1515

16+
import com.graphhopper.routing.ev.Country;
1617
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
1718
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
1819
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
@@ -43,6 +44,7 @@ public class CountryBordersReader implements Serializable {
4344
private final HashMap<String, CountryInfo> ids = new HashMap<>();
4445
private final HashMap<String, ArrayList<String>> openBorders = new HashMap<>();
4546
private final Map<String, Short> isoCodes = new HashMap<>();
47+
private final Map<Short, Country> countries = new HashMap<>();
4648
private Map<Short, String> names = new HashMap<>();
4749
private final HashMap<Long, CountryBordersHierarchy> hierarchies = new HashMap<>();
4850

@@ -422,10 +424,26 @@ private void readIds() {
422424
LOGGER.warn((countries - isoCCA3) + " countries have no ISO 3166-1 CCA3 code assigned.");
423425
} else {
424426
LOGGER.info("ISO 3166-1 CCA3 codes enabled for all countries");
427+
createCountryMap();
425428
}
426429
}
427430
}
428431

432+
private void createCountryMap() {
433+
for (Map.Entry<String, Short> entry : isoCodes.entrySet()) {
434+
String code = entry.getKey();
435+
Short id = entry.getValue();
436+
if (code.length() == 3) {
437+
countries.put(id, Country.valueOf(code));
438+
}
439+
}
440+
}
441+
442+
public Country getCountry(short id) {
443+
return countries.getOrDefault(id, Country.MISSING);
444+
}
445+
446+
429447
/**
430448
* Read information about whether a border between two countries is open. If a border is in the file, then it is
431449
* an open border.

ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/util/parsers/BorderParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ public IntsRef handleWayTags(int fromIndex, int toIndex, IntsRef edgeFlags, Read
126126
countryId2 = getCountryIdFromWay(way, TAG_KEY_COUNTRY2);
127127
}
128128

129+
short countryId = countryId1 == 0 ? countryId2 : countryId1;
130+
131+
if (countryId != 0)
132+
way.setTag("ors:country", cbReader.getCountry(countryId));
129133
borderEnc.setEnum(false, edgeFlags, getBorderType(countryId1, countryId2));
130134

131135
return edgeFlags;

0 commit comments

Comments
 (0)