2

I am working to covert OSM File to get all building's informations in the city.

I am using osm2pgsql package to transform the data. Now I am confused as I have 5 tables :

   - planet_osm_point
   - planet_osm_line
   - planet_osm_roads
   - planet_osm_polygon

https://github.com/openstreetmap/osm2pgsql

I am confused now, how can I get buildings' informations from these tables. What do every table represent ?

3

The names of the tables should be self-explaining:

  • planet_osm_point is a point layer file
  • planet_osm_line is a line layer file
  • planet_osm_roads similar to line, contaning simplified geometries of roads and railways for lower zoom levels
  • planet_osm_polygon contains (multi-)polygons

These tables reflect the OSM data model in the way they can be used GIS software, and for rendering.

You should also have planet_osm_node, _ways and _rels. These represent the OSM data in the same way they are stored on the OpenStreetMap servers for editing.

Building information should be stored in the polygon table. If you want point information, you have to build centroids on the building polygons.

If you need address information, you also have to look into the point table, because the OSM data model allows address information to be put on POIs too, if there is no building polygon, ore one building has several housenumbers. Furthermore, there is the possibility to have address information in the form of lines used for address interpolation.

  • So it's non recommended to go this way.. do you recommend any other better way to convert OSM files to get buildings' addresses – user3378649 Mar 23 '14 at 10:54
  • Why do you think it is not recommended? It is the nature of OSM data that you have to look into several allowed ways of tagging. – AndreJ Mar 23 '14 at 11:01
  • It's not recommended to go through osm2pgsql, SO I am looking for a new way to get addresses from osm files I have – user3378649 Mar 23 '14 at 11:03
2

osm2pgsql is a good option for working with OpenStreetMap data like this, particularly if you have enough data you need a database to store it.

You would find building information in planet_osm_polygon. You could get it using a query like SELECT * FROM planet_osm_polygon WHERE building IS NOT NULL and building != 'no'. For addresses you may find that buildings have addresses mapped as nodes (points) within the building. To get these you'd need joins. One way to do this would be

SELECT array_agg("addr:housenumber") FROM planet_osm_polygon p JOIN planet_osm_node n ON (ST_Within(n.way,p.way)) WHERE p.building IS NOT NULL AND p.building != 'no' AND n."addr:housenumber" IS NOT NULL GROUP BY p.osm_id

This hopefully provides you with a starting point. Obviously the precise queries will need work, depending on your exact requirements, and probably need spatial restrictions and such.

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.