[GIS] How to get the building housenumber from OSM data

labelingopenstreetmapqgis

I've made a map in which buildings in a city are displayed using shapefiles from Geofabrik and unfortunately, none of the shapes contain the housenumber.

When I download the .osm files from Geofabrik the multipolygon layer is empty, but when I download the OSM Data directly via the OSM download tool in QGIS, the multipolygon layer contains buildings, but only if the area where I download it is very small (roughly 30 buildings at a time).

Is there a way to get the multipolygons from OSM other then downloading 30 buildings at a time, then when those are downloaded, extract the housenumber from the other_tags field in the attribute table?

Best Answer

The OpenStreetMap Wiki is your friend: http://wiki.openstreetmap.org/wiki/Map_Features. You can also get a lot of good information from here: https://taginfo.openstreetmap.org/keys/addr:housenumber#combinations.

You may need this:

http://learnosm.org/en/osm-data/osmosis/

and this: https://wiki.openstreetmap.org/wiki/Key:addr

This command line was not tested but can show the way:

osmosis --read-xml your_osm_file.osm.bz2 --tag-filter accept-nodes addr:housenumber=*, addr:street=*, other_tags_you_may_need --write-xml roads.osm

Or you can import to PostgreSQL using osm2pgsql: http://wiki.openstreetmap.org/wiki/Osm2pgsql and use a custom style file: https://github.com/openstreetmap/osm2pgsql/blob/master/default.style

Osm2pgsql is simple to use but you must know how to do a good tunning or it will take a century to import your data.

osm2pgsql -C 2500 -c -d database_target_table -U postgre_user -W -s -S ./your_style_file.style your_osm_file.osm

enter image description here

EDIT: Creating a table to make the things easy. This will be necessary when you need to create a Geoserver Layer.

Pros: Will be easy to locate just what you need.

Cons: You will duplicate the data and will be hard to update later (want to use a view?).

In this example I'll create a table route-tunnels from planet_osm_line with all tunnels. You just need to search for your data in addr:housenumber column at planet_osm_line table. Remember: As far as I know, not all streets will have house numbers. I think it will be in planet_osm_polygon table if you import building:* too.

DROP TABLE IF EXISTS "route-tunnels";
CREATE TABLE "route-tunnels" AS ( 
  SELECT way,highway FROM planet_osm_line 
  WHERE highway IN
  ( 'motorway', 'motorway_link', 'trunk', 'trunk_link', 
    'primary', 'primary_link', 'secondary', 'secondary_link',
    'tertiary', 'tertiary_link', 'residential', 'unclassified' )
  AND tunnel IN ( 'yes', 'true', '1' )
ORDER BY z_order );
CREATE INDEX "route-tunnels_way_idx" ON "route-tunnels" USING gist (way);

enter image description here https://taginfo.openstreetmap.org/keys/building#combinations

Related Question