I've import osm file into database by with this command:

osm2pgsql.exe -c -C 3000 -G -d OSM -U postgres --hstore -S default.style data.osm.pbf

After import I've add required columns:

ALTER TABLE planet_osm_line ADD COLUMN source INTEGER;
ALTER TABLE planet_osm_line ADD COLUMN target INTEGER;

and run pgr_createTopology function over this table:

select pgr_createTopology ('planet_osm_line', .001, 'way', 'osm_id');

Next I find out ids of nearest vertices from generated table planet_osm_line_vertices_pgr (for example vertices with ids 100 and 200) and apply them into routing function like this:

SELECT * FROM pgr_dijkstra('
SELECT osm_id AS id,
     st_length(way) AS cost
    FROM planet_osm_line',
directed := true)

But this give me nothing rows. Can you tell me what I do wrong?

1 Answer 1


First thing - run pgr_analyzeGraph function - as I think it'll tell you topology is incorrect..

Creating correct topology for pg_routing is not as simple as just running pgr_createTopology function - your data must be topologically correct before it, so you have to run pgr_nodeNetwork, but still it's not the best resolution.

It's much better to use topology created by some processors such as osm2pgrouting or osm2po. Last one is best (IMO)

  • At first I used osm2pgrouting, but my current osm file is too large and my ram memory is not size enough. I've decided use osm2pg as alternative but I guess routes generated by osm2po are not very exact. Here is my question about osm2po withou solution: gis.stackexchange.com/questions/229140/… ... and I've tried your advice with pgr_analyzegraph like this: SELECT pgr_analyzegraph('planet_osm_line', 0.001); and function returnet FAIL ... can you tell me what can I do next? I've everything and I am still unsuccessful Feb 21, 2017 at 13:41
  • Denis I answered this linked question now - everything is OK with topology - you have to manually cut first and last line of your route. I'm using osm2po cause (among all) it don't need as much RAM as osm2pgrouting does... It's not a problem to create all Poland using 8G RAM.
    – Jendrusk
    Feb 21, 2017 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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