This is a static archive of our old OSM Help Site. Please post any new questions and answers at community.openstreetmap.org.

How convert a street map(.osm or .shp) into a weighted graph with major street squares as node and length of the street between these nodes as weight?

0

To apply algorithms like Dijkstra on a graph, we need nodes and the distance between each node as weights. In real world these weighted graphs are actual maps and the weights are distance of road. We are looking for a library or a tool which we can be used to convert these map files(.shp or .osm) into a weighted graph or an adjacency matix?

asked 13 Jan '21, 06:27

Kartikeya's gravatar image

Kartikeya
11112
accept rate: 0%


2 Answers:

2

There are a number of tools which will populate the pgrouting schema in PostGIS from OSM data too: osm2pgrouting and osm2po (latter is closed source proprietary software). You can readily interrogate the pgrouting tables with SQL queries and use different algorithms & weights for routing, so although not the most efficient routing method it's quite a good set-up for experimentation.

Anita Graser has written a number of tutorials about pgrouting itself.

answered 13 Jan '21, 13:13

SK53's gravatar image

SK53 ♦
28.1k48268433
accept rate: 22%

Thanks for the help. We just wanted to find the shortest path by a* or dijkstra, but not by any API. We have an osm file and want to extract nodes, edges and the distance between nodes from the same file(python preferably).

(03 Feb '21, 16:02) Kartikeya

1

https://github.com/Tristramg/osm4routing2 is the easiest I've found to create a routing graph from OSM data.

answered 13 Jan '21, 12:39

Richard's gravatar image

Richard ♦
30.9k44279412
accept rate: 18%