[GIS] Working with address data extracted from *.osm

openstreetmaposm2pgsqlpostgispostgresql

My goal is get all the addresses from a certain country, ideally – from all countries, but for now – only from one.

I downloaded an *.osm file from here http://download.geofabrik.de/ for a certain territory which contained a few countries and extracted the data from that file using Osm2pgsql to a Postgres database. There were no errors, all went well.

But now I can't get along with those tables in the db, I can't figure out how actually to query all the addresses from a country I want?

Best Answer

Probably the first thing to do is to import your data again after you have read about addresses in OSM from http://wiki.openstreetmap.org/wiki/Addresses.

Why you should do import again is that the default osm2pgsql style file does not import all the keys which will likely need, for example addr:street https://github.com/openstreetmap/osm2pgsql/blob/master/default.style

Oncy you have imported data with the tags you want to have you can find addresses from osm_points table with

select * from osm_points where addr:housenumber is not null or addr:street is not null.

You can make the query better. More important, however, is to notice that the OSM addresses are very often given for the building polygons. Compare 28 million addresses on nodes and 14 million addressed on ways and relations in http://taginfo.openstreetmap.org/keys/addr%3Ahousenumber. That means that you must run the same address queries also from the osm_polygons table. If you want to get a unified address data you can convert buildings into points with

select ST_Centroid(way) as way from osm polygons where....

Here is something to start with. Consider still if you want to invent everything yourself or if you would rather use some ready made tool like Nominatim http://wiki.openstreetmap.org/wiki/Nominatim.

Related Question