Eventually I came to know that in order to use pgr_createTopology function to create topology network on my imported OSM data (using pg_routing and PostGIS on postgresql), apart from the_geom geometry column I also need the gid integer column which is shipped along with the OSM geometry data.

SELECT pgr_createTopology('ways', 0.00001, 'the_geom', 'gid');

But what is this gid column? I need to run the same pgr_createTopology function on my custom linestring geometry table but I don't know about this gid column.

  • Did you check if the gid of a way equals OSM's way id? I.e. you could check if openstreetmap.org/way/<ID> shows the same object as in your local database.
    – scai
    Sep 23 '14 at 15:48
  • Please repost the correct url. This one is not working.
    – Zia
    Sep 23 '14 at 16:15
  • Sure it is, you have to replace <ID> with the ID you are looking for.
    – scai
    Sep 23 '14 at 16:22
  • Yes, for example http://www.openstreetmap.org/way/114006424 is showing the correct way on the OSM website. But this 114006424 is my db osm_id but I am looking for gid since pgr_createTopology() asks for the gid only.
    – Zia
    Sep 24 '14 at 9:31
  • 1
    @scai and @Gabor My bad! There was some error in my geometry column's SRID and I thought gid to be the reason for my pgr_createTopology()'s error. Thanks by the way.
    – Zia
    Sep 25 '14 at 7:32

It's something like geometry ID, a unique ID to identify each feature in the OSM database. Further references:

What is gid in OpenStreetMap data model?


  • hmm. But when I made a new column in my ways table like this ALTER TABLE ways ADD COLUMN id1 SERIAL; and then run the command SELECT pgr_createTopology('ways', 0.00001, 'the_geom', 'id1');, it gave me ERROR: Condition is not correct error. Logically there shouldn't be any error, because now I am using id1 as my Unique ID column.
    – Zia
    Sep 21 '14 at 14:30
  • Is your id1 column the primary key? The description of pgr_createTopology (docs.pgrouting.org/dev/src/common/doc/functions/…) states that the gid_cname is the "primary key column name of the network table". Sep 21 '14 at 16:05
  • I made id1 as my primary key but still it's not working. By the way, even the by default gid column is also not the primary key.
    – Zia
    Sep 21 '14 at 17:00
  • 1
    I'm pretty sure it is in its original environment (the OSM database). When you export OSM data, you won't get the rules or constraints of the database, just the raw attribute and geometry data. Unfortunately, I haven't encountered the PgRouting plugin of PGSQL yet, so I can't help you out furthermore. Furthermore the other problem isn't directly related to the original question, so I suggest you to ask a new question directly about the pgr_createTopology function. Sep 21 '14 at 17:25
  • Thanks for sharing. I'll post a new question targeting pgr_createTopology() function.
    – Zia
    Sep 23 '14 at 8:50

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.