Add created osm ways to graphhopper without reprocessing de current pbf file

Hi, currently i’m working with graphhopper and OSM data.

I use CGIMap to add new ways to this OSM data. I want to know if there’s a way to add created ways
to graphhopper without restarting the graphhopper and replacing the existing pbf file with a new one with the new
changes.

I hava tried to use a custom OSMReader class to read a OSM file with the new changes using a REST endpoint
and add to the existing data, but doesn’t work properly. There’s something i can do to make this work?
It’s recommended to do something like this?

If you’d like to use CH or LM you’re probably out of luck, because these speedup techniques aren’t so compatible with modifications of the graph. Otherwise there are a few things you need to consider:

  • besides the graph itself you need to update or rebuild the location index, otherwise newly added edges cannot be found

  • updating the in-memory representation of the graph is different to updating the graph that is actually stored on disk. you need to flush the updated data to disk to make it permanent and depending on your requirements you need to think about thread safety for this process and such.

  • GraphHopper removes so called ‘subnetworks’ to prevent snapping to roads that aren’t connected to the main routing graph. Take a look at the prepare.min_network_size parameter. If you modify the graph at runtime this feature won’t work properly, or you need to re-run the subnetwork search as well.

Overall, I’d say updating the graph at runtime is not impossible, but you are working a bit ‘against the system’. GraphHopper is mostly designed for the most common scenario where the graph does not change after the OSM import. If you could anticipate which edges will be ‘added’ later, it might be a good idea to add the edges anyway and just set their weight to infinity. Opening up these edges (lowering their weight) at runtime is possible, even when you are using LM.

Hi, thanks for the reply!

For the last weeks i’ve trying to update the graph and the location index. Currently, i was able to update the graph and add new edges to it, and this part is working for my needs. Now, i’m trying to update the location index, but i’ve stucked at 'cause I can’t find a way to update the location index. I tried to rebuild it but doesn’t worked as i expected. Since then i was trying to update it, but i couldn’t understand the location index enough to make this update.

My doubt is, how could i update the location index in a more “correct” way? When i try to add those new edges to the location index, there’s a sequence when the edges must be or i could add them at the “ending” of the index? If exists a way to do it, i ll’be glad to hear

I think the easiest you can do is just deleting the old location index and creating a new one. Or did you already consider this and it turned out to be too slow?

When i’ve tried to recreate the location index, it occurs an error after recreating it some times, something like array out of bounds exception, i don’t know if it was because i did something wrong when i tried to recreate or if the old index are still occuping the memory after the call of method ‘close’

Thats the major reason i resolved to change the strategy and try to update the index instead of recreating.There’s a “correct” way to how to recreate the location index? How it be the correct way of deleting the location index?

Are you using MMAP? Probably not. Then there is no need to ‘close’ anything. All you need to do is let the old LocationIndex be removed by the garbage collector (make sure there are no references to it) and create a new LocationIndex(Tree) object. The only exception is that if you flush the index to disk you need to delete the old file from your disk, but maybe also overwriting the old file by calling flush for the new location index works.

Powered by Discourse