1

I'm writing a shortest route script in Python using geospatial data from a Postgres DB with PostGIS extension and pgRouting to make the points from OSM data.

I have a path of OSM IDs by points. I got this from downloading OSM XML data from a particular region, importing the data into a database using osm2pgrouting, calculating the shortest route in my script, and using the OSM ID as the main point of identification. This all being stored in a PostGIS database.

If I had an array of, in order from 0-n for the path, the OSM IDs of all the points for the shortest route, how could I create a line to line up with the roads in OSM for the path?

I've looked at ST_MakeLine, but my worry with that is it will output like the picture below, and not connecting the actual roads. I want the path to actually map with the actual roads and not just create a line between points where a road doesn't exist.

enter image description here

What should I do?

2
  • usually all shortest path functions in pgRouting return a table including visited vertices (node ids) and traversed segments (edge ids) in sorted, consecutive order (as described e.g. here for pgr_dijkstra function)
    – geozelot
    Commented Oct 9, 2017 at 9:23
  • meaning that you can query your roads layer (from within the script) for the returned ids ('edge' in the result table), ordered by the 'seq' ids (and e.g. combine them with st_linemerge or st_union if necessary)
    – geozelot
    Commented Oct 9, 2017 at 9:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.