So evechainz, the system is internally creating own IDs (int) of the original OSM-Node Ids (long) while creating the Graph. . This is because of saving memory and to have a efficient data structure with own IDs counting from 0 to X not something like “234345643”
(if you work with OpenStreetMap the graph probably is created with the help of OSMReader (a DataReader) of the “graphhopper-reader-osm” packages. )
in https://github.com/karussell/graphhopper-osm-id-mapping
Karusell have showed how to make a match between the internal Edge IDs and the original Edge IDs in the proccess of reading the nodes and edges with the OSMReader class
I extended the Class “MyGraphhopper” from: https://github.com/karussell/graphhopper-osm-id-mapping
through:
Create own DataAccess-Object in the class:
private DataAccess nodeMapping;
and create the method for getting the original Node:
public long getOSMNode(int internalNodeId) {
long pointer = 8L * internalNodeId;
return bitUtil.combineIntsToLong(nodeMapping.getInt(pointer), nodeMapping.getInt(pointer + 4L));
}
and expand the DataReader within the class:
@Override
protected DataReader createReader(GraphHopperStorage ghStorage) {
OSMReader reader = new OSMReader(ghStorage) {
{
edgeMapping.create(1000);
// TODO this has to be added:
nodeMapping.create(1000);
}
..............
@Override
protected void storeOsmNodeID(int nodeId, long osmNodeId) {
if (nodeId >= 0) {
super.storeOsmNodeID(nodeId, osmNodeId);
long pointer = 8L * nodeId;
nodeMapping.ensureCapacity(pointer + 8L);
nodeMapping.setInt(pointer, bitUtil.getIntLow(osmNodeId));
nodeMapping.setInt(pointer + 4, bitUtil.getIntHigh(osmNodeId));
}
}
@Override
protected void finishedReading() {
super.finishedReading();
edgeMapping.flush();
// TODO add the flushing of the datastructure here:
nodeMapping.flush();
}
Now you also have to expand the OSMReader:
int addTowerNode(long osmId, double lat, double lon, double ele) {
if (nodeAccess.is3D())
nodeAccess.setNode(nextTowerId, lat, lon, ele);
else
nodeAccess.setNode(nextTowerId, lat, lon);
int id = -(nextTowerId + 3);
getNodeMap().put(osmId, id);
//TODO
storeOsmNodeID(nextTowerId, osmId);
nextTowerId++;
return id;
}
as well you need the storeOsmNodeID(…) which is overwriten/extended by the code we wrote before in “MyGraphhopper”…
protected void storeOsmNodeID(int nodeId, long osmNodeId) {
if(getNodeIdToOsmNodeIdMap().get(nodeId)!=0L && getNodeIdToOsmNodeIdMap().get(nodeId)!=osmNodeId)
System.err.println(nodeId+": conflict: old: "+getNodeIdToOsmNodeIdMap().get(nodeId)+" new: "+osmNodeId);
getNodeIdToOsmNodeIdMap().put(nodeId, osmNodeId);
}
and you have to add to intruduce the data structure and it’s getter:
protected IntLongMap nodeIdToOsmNodeIdMap;
private IntLongMap getNodeIdToOsmNodeIdMap() {
if (nodeIdToOsmNodeIdMap == null)
nodeIdToOsmNodeIdMap = new GHIntLongHashMap((int) getNodeMap().getSize(), 0.5f);
return nodeIdToOsmNodeIdMap;
}
The reason Iam not sending a whole code or repository here, is that I have changed the core in several points. So I can not give you a working example. But this should be all snippets to make it work.
If it is interessting we can put it in the the common repository, maybe I can organize to push it.
(@karussell but you would need to help me ^^, I have no much experience so far with repos ).
So with this code you should be able to extend the project of karussell, and to use the MyGraphhopper in your project as Graphhopper-Instace