Skip to content

Commit 4e62187

Browse files
committed
feat: read country tags from nodes
1 parent dfd5788 commit 4e62187

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class ORSOSMReader extends OSMReader {
3939
private boolean processNodeTags;
4040
private final OSMDataReaderContext readerCntx;
4141

42+
//FIXME: big regular hashmaps should be avoided because they don't support MMAP
4243
private final HashMap<Long, HashMap<String, String>> nodeTags = new HashMap<>();
4344

4445
private boolean processGeom = false;
@@ -67,6 +68,7 @@ public ORSOSMReader(GraphHopperStorage storage, GraphProcessContext procCntx) {
6768
// Look if we should do border processing - if so then we have to process the geometry
6869
for (GraphStorageBuilder b : this.procCntx.getStorageBuilders()) {
6970
if (b instanceof BordersGraphStorageBuilder) {
71+
extraTagKeys.add("country");
7072
this.processGeom = true;
7173
}
7274

ors-engine/src/main/java/org/heigit/ors/routing/graphhopper/extensions/storages/builders/BordersGraphStorageBuilder.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.locationtech.jts.geom.LineString;
2828

2929
import java.util.ArrayList;
30+
import java.util.HashMap;
3031
import java.util.Map;
3132
import java.util.MissingResourceException;
3233

@@ -42,6 +43,9 @@ public class BordersGraphStorageBuilder extends AbstractGraphStorageBuilder {
4243
private static final String PARAM_KEY_OPEN_BORDERS = "openborders";
4344
private static final String TAG_KEY_COUNTRY1 = "country1";
4445
private static final String TAG_KEY_COUNTRY2 = "country2";
46+
private static final int EMPTY_NODE = -1;
47+
private static final int TOWER_NODE = -2;
48+
private HashMap<Integer, String> wayNodeTags;
4549

4650
private BordersGraphStorage storage;
4751
private CountryBordersReader cbReader;
@@ -138,6 +142,24 @@ public void processWay(ReaderWay way, Coordinate[] coords, Map<Integer, Map<Stri
138142
way.setTag(TAG_KEY_COUNTRY2, countries[0]);
139143
}
140144
}
145+
146+
wayNodeTags = new HashMap<>();
147+
if (nodeTags != null) {
148+
for (Integer internalNodeId : nodeTags.keySet()) {
149+
int nodeId = convertTowerNodeId(internalNodeId);
150+
if (nodeId == EMPTY_NODE)// skip non-tower nodes
151+
continue;
152+
Map<String, String> tagPairs = nodeTags.get(internalNodeId);
153+
wayNodeTags.put(nodeId, tagPairs.get("country"));
154+
}
155+
}
156+
}
157+
158+
private int convertTowerNodeId(int id) {
159+
if (id < TOWER_NODE)
160+
return -id - 3;
161+
162+
return EMPTY_NODE;
141163
}
142164

143165
/**
@@ -172,6 +194,22 @@ public void processEdge(ReaderWay way, EdgeIteratorState edge) {
172194
}
173195
storage.setEdgeValue(edge.getEdge(), type, start, end);
174196
}
197+
198+
int egdeId1 = edge.getBaseNode();
199+
int edgeId2 = edge.getAdjNode();
200+
String countryCode1 = wayNodeTags.get(egdeId1);
201+
String countryCode2 = wayNodeTags.get(edgeId2);
202+
try {
203+
start = Short.parseShort(String.valueOf(cbReader.getCountryIdByISOCode(countryCode1)));
204+
end = Short.parseShort(String.valueOf(cbReader.getCountryIdByISOCode(countryCode2)));
205+
} catch (Exception ignore) {
206+
// do nothing
207+
} finally {
208+
if (start != end) {
209+
type = (short) 1;//FIXME (cbReader.isOpen(cbReader.getEngName(startVal), cbReader.getEngName(endVal))) ? (short) 2 : (short) 1;
210+
}
211+
storage.setEdgeValue(edge.getEdge(), type, start, end);
212+
}
175213
}
176214
}
177215

0 commit comments

Comments
 (0)