I'm wondering how to generate with the given lonlat in OSM PostGIS entities.

In pgrouting's website, they are telling that source and target are identifier of the vertex but not telling if this an osm_id for OSM database or any. My only given to generate is lonlat of the potential source/target. I'm using osm2po to create routable database.

Can anyone give me a clue, so that I can make my map more dynamic?


1 Answer 1


In case you haven't tried it yet, the pgRouting Workshop is always a good place to get started.

When you used osm2po to convert your OSM data, then source and target attributes are already there and ready to use.

Sometimes the vertices table, that contains all source and target ID's, is useful to find the nearest vertex from a geographic point. The osm2po SQL file does not contain this table, but there is a function to create it:

SELECT pgr_createVerticesTable('<tablename>','geom_way','source','target');

To find the nearest node is now a simple PostGIS query.

  • Of course keep in mind, that the nearest node is not always best resolution - if yours starting point is near one-way street you have to start from target point of this edge and stop at the source point of edge nearest to stop point
    – Jendrusk
    Aug 1, 2014 at 8:11
  • Great day to all of you. I'm just wondering why the route line is not the perfect. Sometimes there are edges connected to the one node and sometimes the result route line is not aligned to the road. Any idea why these happening? Aug 3, 2014 at 20:29

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.