4

I spent days looking in all questions here and trying tutorials. I need to build a graph for a region (It will be my input in simulation) I downloaded Postgresql and Postgis and osm2pgsql. Now i can load .osm files into a database. I want to have a complete database with roads ids so i can generate a table of edges and nodes then build my graph

nodes = intersections and edges = roads for a city using python.

Please any detailed help with steps.I saw a lot of keywords (Postgresql/postgis, Networkx, QGIS ..) but i couldn't manage to assemble a good tutorial

I am a very beginner.

4 Answers 4

3

If you're a very beginner you should try this tutorial of osm2po by @Underdark

Osm2po will give you ready to use graph from osm data as sql script file, all you have to do is load it into database via psql -f command.

In this table every single record is edge. Every edge has 2 vertices source and target - coordinations of this points are in column x1,y2 and x2,y2.

If you need seperate table with vertices just run:

  create table vertices as 
    select source as ID, st_makepoint(x1,y1) as geom from edges_table
    union
    select target as ID, st_makepoint(x2,y2) as geom from edges_table
8
  • thank you, i followed the tutorial and it worked well for me. Now i can see a table full of columns with roads ids .. What next ? I really need a simple sql database , just a table with nodes and edges to build a graph. Any suggestions ?
    – user33286
    Commented Jul 8, 2014 at 15:07
  • This table is your graph - more info about clazz and speed you'll find in config file of osm2po, cost is time of driving egde with default speed in hours. You don't need table with points since source is id of start point and x1,y1 is coordinates of this point, the same with target, x2, y2. I don't know what is your point and what kind of simulation you want to do, but this table is ideal to feed pg_routing e.g.
    – Jendrusk
    Commented Jul 8, 2014 at 17:23
  • Thank you for your answer, My point is to build a graph where vertices are intersection points in area and edges are the roads. This will be my input for a simulation of networks with ns-3. That's why i need it as simple as possible. Should i treat myself the database with python for example, and try to extract vertices and edges ?
    – user33286
    Commented Jul 9, 2014 at 9:02
  • I want to mention that with osm2po i got one table "at_2po_4pgr" but with osm2pgsql I got 4 tables: planet_osm_point/ line/ road/polygon . I think the second case suit me better, points are stations or intersections, and lines/roads may be edges...
    – user33286
    Commented Jul 9, 2014 at 9:10
  • These are two seperate things - osm2pgsql is converting full osm data into database (e.g. to create full map with mapnik), but imported roads are not network graph, osm2po is converting only roads into network graph which you can use to create network analysis. Each row in table at_2po_4pgr is single edge, if you need seperated vertices you can create it as select source, st_makepoint(x1,y1) from at_2po_4pgr. There is some misunderstanding - I'm telling you - 'here is your's table of vertices and edges' and your telling me 'ok, but I need vertices and edges' :)
    – Jendrusk
    Commented Jul 9, 2014 at 9:53
3

http://osm-traffic.com/ allows direct download of graph data from OpenStreetMap in json format.

Disclaimer: I work with the company who developed, it might become a pay service.

2

You should check the pgRouting project. There is a great step to step workshop/tutorial. http://workshop.pgrouting.org/

1
  • I am working on mac OS X mavericks. I have already Osm2pgsql and Osm2po
    – user33286
    Commented Jul 8, 2014 at 15:21
2

I use both GraphHopper AND Pg_Routing

Pg_Routingis a lot more flexible but is relatively slower (Depending on the size of the area). You can change costs on an edge in real time

GraphHopper buids graphs from an OSM Extract and has its own built in web Server, so is very quick to get up and running ..

1

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.