Let's say I'm exporting features from my PostGIS DB like so:

SELECT ST_AsGeoJSON(*)::jsonb
FROM planet_osm_line
WHERE [conditions]

What I'm trying to achieve here is to include the "id" property associated with the way from planet_osm_ways. Now, I know that I can create a primary key and be done with it but I want to stick to the actual information as much as possible.

Is this too much of a hassle and I should just stick to creating a manual primary key, or is it fairly easy to do?
How can I make the connection between the two tables? I tried to do an inner join but realized that planet_osm_ways.nodes is of type bigint[] and can't be compared to planet_osm_line.way.

  • 1
    See this answer – John Powell Mar 3 '20 at 13:02
  • Thanks, @JohnPowell! is gid something I should create manually? it seems my DB doesn't recognize it. I'm working with postgresql 12 and postgis 3.0 I used osm2pgsql to insert the info into the DB, if that helps in any way. Should I have included some extra config there? – Oren_C Mar 3 '20 at 13:10
  • Well, it's whatever field you have in your DB that you want mapped to "id", that was just example code, which happened to use gid. – John Powell Mar 3 '20 at 13:15

Your Answer

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

Browse other questions tagged or ask your own question.