0

I am new in GIS, but I need extract addresses (city, street, housenumber, lat, lon) from my osm file. Can you give me advice what is the best way to do that? I found project openaddresses, but a lot of addresses of my area is missing.

  • wiki.openstreetmap.org/wiki/Key:addr adresses are part of the tags used in osm. If you import an osm file into postgresql/postgis, you should find that as a table column: wiki.openstreetmap.org/wiki/Osm2pgsql There's also a solution using qgis, decribed here: qgistutorials.com/en/docs/downloading_osm_data.html – Andreas Müller Feb 15 '17 at 11:19
  • Due to the crowd-sourced nature of the datasets you mention, you may well find that the are incomplete or inaccurate. Depending on what you are using this data for and how accurate it needs to be, your best option might be to get your address data from a more official source. – Matt Feb 15 '17 at 11:20
  • If you need full addresses from OSM and not just address parts (sometimes only house number and street name are present) then you will have to use an OSM-based geocoder such as Nominatim. – scai Feb 15 '17 at 11:52
  • I've implemented full text search with fuzzy, so it works well, but I need only addresses with coordinates as source ... I've tried import osm with osm2pgsql, but some cities in my country are missing – Denis Stephanov Feb 15 '17 at 12:09
  • Can you tell us examples of missing cities? – scai Feb 15 '17 at 15:43
1
  1. check if this addresses exists in osm project (osm.org website).
  2. If yes then keep in mind that addresses could be tagged on points and polygons (buildings) so you have to union data from 2 tables.
  3. Third is that in OSM not every address have to be complete - you could get only point with number but without city or street so you have to get rest of data from spatial relationship (nearest street or city boarder)

If you'll write which addresses you can see in osm and don't see in your database it'll be simpler to help you.


EDIT:

Assuming you're interested only in 100% sure addresses your query looks fine, but still you'll not get addresses where street and/or city is not set in tags. You can try as follows, but keep in mind that this values are not 100% sure... Also make sure you have proper indexes (including spatial) - without this query will run about 2 centuries :)

 select 
     osm_id, 
     name, 
     "addr:country" as country, 
     coalesce ("addr:city",(select name from planet_osm_polygon cit where st_intersects(adpol.way, cit.way) and admin_level = '8' limit 1)) as city, 
     coalesce ("addr:street",(select name from planet_osm_line str where name != '' and highway != '' order by st_distance(adpol.way,str.way) limit 1)) as street, 
     "addr:housenumber" as housenumber, 
     "addr:postcode" as postcode,
     st_x(st_transform(ST_Centroid(way), 4326)) as lon,
     st_y(st_transform(ST_Centroid(way), 4326)) as lat
 from planet_osm_polygon adpol
 where "addr:housenumber" <> ''
 union 
 select
     osm_id,
     name,
     "addr:country" as country, 
     coalesce ("addr:city",(select name from planet_osm_polygon cit where st_intersects(adpoi.way, cit.way) and admin_level = '8' limit 1)) as city, 
     coalesce ("addr:street",(select name from planet_osm_line str where name != '' and highway != '' order by st_distance(adpoi.way,str.way) limit 1)) as street,
     "addr:housenumber" as housenumber, 
     "addr:postcode" as postcode,
     st_x(st_transform(way, 4326)) as lon,
     st_y(st_transform(way, 4326)) as lat 
 from planet_osm_point adpoi
 where  "addr:housenumber" <> ''
  • Can you link to a screenshot from OSM where housenumbers can be seen which are still missing in your data? – AndreJ Feb 15 '17 at 14:48

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.