[GIS] How to get address coordinates from OSM

geocodinggeoextopenlayers-2openstreetmap

I've got an osm file containing the city I live in. Now I've got a tool to render and display it in the browser (mapnik+postgis+tilecache+openlayers+geoext) and the task is to make an address search.

I know that I can use nominatim (and actualy I use it for now), but I'd like to create my own service.

So the question is: how can I (if I can) get all adresses and their coordinates from the osm file or it's exported to postgis version?

Best Answer

Have a look to see if there are any columns in your database named "addr" or similar. If there are then you may be able to query the database directly and isolate these rows.

If not, you probably need to create a database schema with address tags included from scratch. Broadly how I might go about doing it is as follows:

  1. Run the raw .osm datafile through Osmosis, filtering out only those tags with an addr:* prefix. Probably using the --tag-filter. It might be easier to filter out only points, but some polygons may have the tag as well.
  2. As part of the same osmosis task, dump the resulting filtered data into a postgis database. You may need to develop a custom schema for the addresses, as they may not be imported by default
  3. Generalise the resulting data if you have line or polygon objects (e.g. get centroid) so that each address has one co-ordinate.
  4. Query the database for your geocoded addresses

Steps 1 and 2 could be replaced by creating your own osm2pgsql schema, which might be easier.

If this seems like a lot of work that's because it is. AFAIK there are relatively few osm tools to support getting addresses like this at the moment, but happy to be corrected. I would check before you start that it's going to be worth your while - i.e. people have been busy in your area tagging addresses on the map and address tags are not very sparse.