[GraphHopper] ExtendedStorage for OSM ids
Diego Guidi
diegoguidi at gmail.com
Mon Apr 21 19:29:56 UTC 2014
On Fri, Mar 28, 2014 at 2:43 PM, Bruno Carle <brunocarle at yahoo.com> wrote:
> At the moment I would like to be able to blacklist both nodes and edges, so
> I will stick with the ExtendedStorage.
I've made a slightly different thing.
I've created a "support map" that stores osmid for each node, using
this code (in the extended OsmReader that is similar that the one you
posted):
@Override
protected boolean addNode(OSMNode node) {
boolean added = super.addNode(node);
if (!added) {
return false;
}
long osmid = node.getId();
int graphid = this.getInternalNodeIdOfOsmNode(osmid);
map.put(graphid, osmid);
return true;
}
The I've stored this map as an external "support file" inside graph folder:
private File createSupportFile() throws IOException {
String dir = this.getGraphStorage().getDirectory().getLocation();
File file = new File(dir + "/support");
String path = file.getAbsolutePath();
if (file.exists()) {
file.delete();
}
if (!file.createNewFile()) {
throw new IllegalStateException("file not created: " + path);
}
String newline = System.getProperty("line.separator");
Writer fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw);
try {
for (Integer key : map.keySet()) {
Long val = map.get(key);
bw.write(String.format("%d|%d%s", key, val, newline));
}
} finally {
bw.close();
}
return file;
}
Pretty unelegant (ExtendedStorage is the right way to do things, I
suppose) but simple and well working for small graphs (my osm source
file is 22mb).
Hope this can help someone.
Diego Guidi
More information about the GraphHopper
mailing list