NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

I want to set up a simple reverse geocoding system and was thinking of using osm2pgsql to import the data (possibly of the whole planet). I noticed that the data is very large and slow to import. Is it possible to import just the street data required to perform reverse geocoding?

If yes how do I go about it, and how do I go about maintaining the database up to date (with osmosis or any alternative) without importing buildings or POIs which are not needed for reverse geocoding? My intention of course is to keep the database size down to only the data I need.

asked 02 Feb '17, 00:14

jbx1's gravatar image

jbx1
11335
accept rate: 0%


The main OpenStreetMap geocoder, Nominatim, is relatively complex and uses much more than just street data. You will likely re-invent the wheel when you build your own (reverse) geocoder, and you'll make a couple mistakes that Nominatim has made and learnt from in the past. But if you really want to set up your own:

osm2pgsql has something called a "style file" which determines what to import. You could copy the default style file and remove everything that isn't a highway. Alternatively, you could use osmosis or osmfilter to first create a subset of the planet file that contains only the bits that interest you, and then import.

Note however that this approach will not give you house numbers or an admin hierarchy, i.e. you will be able to find out that a given location is in "Main Street" but not which city, county, country (or post code for that matter). If you want the admin hierarchy, you have to import boundary=administrative objects as well. Additionally some small villages or city quarters are mapped not as boundary=administrative but as landuse=residential or even as a single place node, all of which Nominatim would honour in its reverse geocoding response.

permanent link

answered 02 Feb '17, 07:41

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273
accept rate: 23%

Thanks for your reply. In actual fact I would like to use Nominatim, but I was wondering if I can remove stuff which is not needed, like building information, points of interest etc. to reduce the database size. I only need reverse geocoding (not geocoding). I had a look at Nominatim's reverse geocoder and it seems to be just an sql query, enlarging the diameter iteratively if the initial query doesn't return any results from the placex table. The extra stuff it seems to do is that it interpolates house numbers if the house cannot be determined directly, and if it still cannot determine it, and the country code is in the US, it uses the TIGER data set to try and find the house. There is an extra check for whether the place is too small, in which case its parent is taken. Other than that there doesn't seem to be much.

My application is related to transportation movement tracking, so going down to the granularity of house number is not really needed (at least not at this point). I will need village, city, country etc. of course.

Would Nominatim still work if I only import highways, administrative boundaries and maybe the special land use residential boundaries?

(02 Feb '17, 10:24) jbx1
1

I agree with Frederick's approach. By default Nominatim also fills search index tables only used for forward search (think: word => list of places). The logic is too deep in the import and data update steps that it can't be easily disabled. And while deleting the (for reverse unused) tables after the initial update would work the updates would fail. As Richard points out have a look at Photon, I think there's monthly data dumps to import now. Takes 60GB disc space.

(02 Feb '17, 11:16) mtmail

You may find it easiest to set up a local instance of Photon (https://github.com/komoot/photon), which has reverse geocoding capabilities and for which you can download pre-made data dumps. Note however that Photon development appears to be rather in abeyance.

permanent link

answered 02 Feb '17, 10:12

Richard's gravatar image

Richard ♦
30.9k44279412
accept rate: 18%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×263
×85

question asked: 02 Feb '17, 00:14

question was seen: 4,226 times

last updated: 02 Feb '17, 11:16

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum