Reading nodes and edges from DB?

I have a postgreSQL db with nodes (lat,long,id,edge count)(Only tower nodes are stored) and edges (id,startnode,endnode), originally extracted from an osm file, how would it be possible to use these for map matching?
Is it correct to say that it is not possible to use the database directly even if I would generate virtual nodes since accessing it is too slow in comparison to the data structures normally used?
Instead I can make a reader like reader-osm but from my db and use dummy data for the missing information (make all roads car roads for example.)?
Or is there a better solution?

Thank you in advance!

1 Like

Do you want to associate properties to every edge ID or what is the use case?

You can make GH return the edge IDs (convert them from traversal keys) and then fetch the GH edgeIDs from the DB (if you have just OSM nodes and edges IDs stores it is not yet possible).

Is it correct to say that it is not possible to use the database directly even if I would generate virtual nodes since accessing it is too slow in comparison to the data structures normally used?

The described procedure should be fast enough. But everything that involves calls in the algorithm or map matching process will make it too slow.

Instead I can make a reader like reader-osm but from my db and use dummy data for the missing information (make all roads car roads for example.)?

What do you mean here?

Or is there a better solution?

Yes, you can work completely without a DB but this requires deeper GH knowledge.

My apologies for the unclear explanation.

The use case is a follows: I have nodes and edges extracted from osm files (stored in a db) which are used to manually navigate between by users. However I would like to offer a way to create routes from gpx files.

Ideally I would do the map-matching directly on my own nodes and edges dataset If I use the original osm files, I will have to map the result back onto my own set of nodes and edges which creates a whole new problem. So I am trying to see if it is possible to use GraphHopper map matching for this, and how exactly I can best use the nodes and edges I have.

Thank you for the help!

I have nodes and edges extracted from osm files (stored in a db) which are used to manually navigate between by users.

Sorry, now I’m confused. Do you mean you currently do shortest path calculation within your database?

Ideally I would do the map-matching directly on my own nodes and edges dataset

Why is there a difference between your IDs and OSM IDs? Why couldn’t you feed graphhopper with the same source and e.g. attach the OSM IDs in the GH storage?

Sorry, now I’m confused. Do you mean you currently do shortest path calculation within your database?

The nodes are used in a game where the user choose a direction at every node and navigate the map. There is no shortest path calculation.

Ideally I would do the map-matching directly on my own nodes and edges dataset

My nodes are a subset of the OSM ID’s, anything but roads for cars are removed. So I would like to feed Graphhopper with this subset I have.

What does subset mean? Will the OSM ID 1234 change to 3048? If not, then I see no problem in just doing the import with the same OSM source and attach OSM IDs in GraphHopper somehow.

Or you can write a new DataReader (i.e. a new import mechanism) feeding nodes and edges directly from your database. Have a look in OSMReader or PrinctonReader

Thank you

What does subset mean? Will the OSM ID 1234 change to 3048? If not, then I see no problem in just doing the import with the same OSM source and attach OSM IDs in GraphHopper somehow.

The OSM id’s are not changed. But for example all nodes of cycling lanes are removed.

Or you can write a new DataReader (i.e. a new import mechanism) feeding nodes and edges directly from your database. Have a look in OSMReader or PrinctonReader

This was indeed what I planned on doing however this would mean I need to keep the Graphhopper instance running since the import will have to be redone whenever graphhopper is started, correct?

The OSM id’s are not changed. But for example all nodes of cycling lanes are removed

If this is the case you can avoid implementing a custom DataReader IMO.

This was indeed what I planned on doing however this would mean I need to keep the Graphhopper instance running since the import will have to be redone whenever graphhopper is started, correct?

Not sure what you mean here. GraphHopper does the ‘import’ once and afterwards stores this in a custom file format so that the next time you start it it will be very fast and can avoid the costly import. If you mean you don’t want a down time you can create two GraphHopper instances within one JVM or just two JVMs or servers etc.

Hey Router,
We’re facing the same problem and was wondering how this was solved?
Thanks!

P.S
we’re using http://wiki.openstreetmap.org/wiki/Osmconvert to get partial maps, but getting them directly from postgres will be much easier