OpenStreetMap Nominatim Server For Geocoding - Leave No Bit Unturned
OpenStreetMap Nominatim Server For Geocoding - Leave No Bit Unturned
OPENSTREETMAP
NOMINATIM SERVER FOR
GEOCODING
2015-03-19 | KORTSI | 31 COMMENTS
5.00 avg. rating (98% score) - 9 votes
Here’s how to install the OpenStreetMap Nominatim service on
your own server. It can be used to geocode and reverse geocode
addresses and map coordinates. You will also get a web interface
which loads map tiles from openstreetmap.org while doing
geocoding requests using your own server.
I was faced with thousands of geocoding requests per hour, and with
such a high volume it is not wise to burden the global OSM servers.
Even with aggressive caching it would have potentially been too
much.
I will use Ubuntu 14.04 LTS as the platform. Just a basic install with
ssh server. We will install Apache to serve http requests. Make sure
you have enough disk space and RAM to hold the data and serve it
ef ciently. I used the Finland extract, which was about a 200 MB
download. The resulting database was 26 GB after importing,
indexing and adding Wikipedia data. The Wikipedia data probably
actually took more disk space than the OSM data. My server has 4
GB RAM, which seems to be enough for this small data set.
1 Sofware requirements
2 Kernel tuning
3 PostgreSQL tuning
4 Dedicated user
5 Database users
6 Download and Compile Nominatim
6.1 Clone the Repository from Github
6.2 Compile Nominatim
6.3 Con gure Local Settings
7 Download Data
8 Import Data
9 Database Production Settings
10 Create the Web Site
10.1 Apache con guration
10.2 Install the Nominatim Web Site
11 Enable OSM Updates
12 Wrap Up
12.1 Useful links
Sofware requirements
PostgreSQL with PostGIS extension:
1 apt-get install \
2 apache2 php5 php-pear php5-pgsql php5-json php-db
1 apt-get install \
2 wget git autoconf-archive build-essential \
3 automake gcc proj-bin
Needed libraries:
1 apt-get install \
2 libxml2-dev libgeos-dev libpq-dev libbz2-dev libtool \
3 automake libproj-dev libboost-dev libboost-system-dev \
4 libboost-filesystem-dev libboost-thread-dev \
5 libgeos-c1 libgeos++-dev lua5.2 liblua5.2-dev \
6 libprotobuf-c0-dev protobuf-c-compiler
Kernel tuning
We must increase kernel shared memory limits. Also we’ll reduce
swappiness and set the kernel memory overcommit to be a bit more
conservative. Make sure you have anough swap space, more than
physical memory is a good idea.
1 sysctl -w kernel.shmmax=4404019200
2 sysctl -w kernel.shmall=1075200
3 sysctl vm.overcommit_memory=2
4 sysctl vm.swappiness=10
5
6 echo "kernel.shmmax=4404019200" >> /etc/sysctl.conf
7 echo "kernel.shmall=1075200" >> /etc/sysctl.conf
8 echo "vm.overcommit_memory=2" >> /etc/sysctl.conf
9 echo "vm.swappiness=10" >> /etc/sysctl.conf
PostgreSQL tuning
The following directives were set in
/etc/postgresql/9.3/main/postgresql.conf:
1 shared_buffers = 2048MB
2 work_mem = 50MB
3 maintenance_work_mem = 1024M
4 fsync = off # dangerous!
5 synchronous_commit = off
6 full_page_writes = off # dangerous!
7 checkpoint_segments = 100
8 checkpoint_timeout = 10min
9 checkpoint_completion_target = 0.9
10 effective_cache_size = 2048M
There are two truly dangerous settings here. Setting fsync off will
cause PostgreSQL to report successful commits before the disk has
con rmed the data has been written successfully. Setting
full_page_writes off exposes the database to the possibility of
partially updated data in case of power failure. These options are
used here only for the duration of the initial import, because setting
them so makes the import much faster. Fsync and full page writes
must be turned back on after the import to ensure database
consistency.
The synchronous_commit also jeopardizes the durability of
committed transactions by reporting successful commits to clients
asynchronously, meaning that the transaction may not have been
fully written to disk. It does not compromize consistency as the two
previous directives discussed. It just means that in the case of power
failure, some recent transactions that were already reported to the
client as having been committed, may in fact be aborted and rolled
back. The database will still be in a consistent state. We’ll leave it off
because it speeds up the queries, and we don’t really care about it in
this database. We can always rebuild it from scratch. But if you have
other important databases in the same database cluster, I would
recommend turning it back on as well, since the setting is cluster-
wide.
Dedicated user
We’ll install the software under this user’s home directory (user id
“nominatim”).
Database users
We will also make “nominatim” a database user, as well as the
already created “www-data” (created by the apache2 package).
1 su - postgres
1 su - nominatim
Set some environment variables. We’ll use these later. These are the
download locations for les and updates. Lines 3 and 4 below are for
Finland. Customize to your needs.
Also set the BASE_URL to point to your server and install directory.
The last forward slash seems to be important.
1 WIKIPEDIA_ARTICLES="http://www.nominatim.org/data/wikipedia_artic
2 WIKIPEDIA_REDIRECTS="http://www.nominatim.org/data/wikipedia_redi
3 OSM_LATEST="http://download.geofabrik.de/europe/finland-latest.os
4 OSM_UPDATES="http://download.geofabrik.de/europe/finland-updates"
5 BASE_URL="http://maps.example.org/nominatim/"
Compile Nominatim
Simply:
1 ./autogen.sh
2 ./configure
3 make
The last four de nitions are only required if you are going to do
incremental updates.
Download Data
OpenStreetMap data (about 200 MB for Finland):
The OSM data is all that is really required. The rest below are
optional.
Import Data
The utils/setup.php will create a new database called “nominatim”
and import the given .pbf le into it. This will take a long time
depending on your PostgreSQL settings, available memory, disk
speed and size of dataset. The full planet can take days to import on
modern hardware. My small dataset took a bit over two hours.
1 ./utils/setup.php \
2 --osm-file data/latest.osm.pbf \
3 --all --osm2pgsql-cache 1024 2>&1 \
4 | tee setup.log
The messages will be saved into setup.log in case you need to look at
them later.
If you had the Wikipedia data downloaded, the setup should have
imported that automatically and told you about it. You can import
the special phrases data if you downloaded it earlier using these
commands:
1 maintenance_work_mem = 128M
2 fsync = on
3 full_page_writes = on
Apply changes:
1 mkdir /var/www/html/nominatim
2 chown nominatim:www-data /var/www/html/nominatim
3 chmod 755 /var/www/html/nominatim
4 chmod g+s /var/www/html/nominatim
1 <VirtualHost *:80>
2 ServerName maps.example.org
3 ServerAdmin [email protected]
4 DocumentRoot /var/www/html
5
6 ErrorLog ${APACHE_LOG_DIR}/error.log
7 CustomLog ${APACHE_LOG_DIR}/access.log combined
8
9 <Directory "/var/www/html/nominatim">
10 Options FollowSymLinks MultiViews
11 AddType text/html .php
12 </Directory>
13 </VirtualHost>
1 apache2ctl restart
1 su - nominatim
2 cd Nominatim
Run the setup.php with the option to create the web site:
At this point, the site is ready and you can point your browser to the
base URL and try it out. It should look something like this:
Enable OSM Updates
We will con gure a cron job to have the database updated
periodically using diffs from Geofabrik.de. As the nominatim user:
1 rm settings/configuration.txt
2 ./utils/setup.php --osmosis-init
1 crontab -e
Wrap Up
That’s it! You can get JSON or XML data out of the database with
http requests. A couple of examples:
Forward geocoding:
http://maps.example.org/nominatim/search.php?
format=jsonv2&q=mannerheimintie, helsinki
Reverse geocoding:
http://maps.example.org/nominatim/reverse.php?
format=jsonv2&lat=60.1805&lon=24.9434
Useful links
http://www.openstreetmap.org
http://nominatim.openstreetmap.org/
http://wiki.openstreetmap.org/wiki/Nominatim
http://wiki.openstreetmap.org/wiki/Nominatim/Installation
https://github.com/cyclestreets/nominatim-install
SHARE:
More
LIKE THIS:
Like
Be the first to like this.
31 THOUGHTS ON “OPENSTREETMAP NOMINATIM SERVER
FOR GEOCODING”
Thanks!
kortsi
2015-03-26 AT 14:03
64-bit Ubuntu
Gustavo Ferreira
2015-04-08 AT 02:12
When I try to access the reverse.php get this: “{” error “:” Unable
to geocode “}”. I followed all the steps of your article, which can
be?
kortsi
2015-04-08 AT 09:40
That may mean there’s something wrong with your query. Did
you give the “lat” and “lon” parameters? Those are required.
imagen of website
http://i60.tinypic.com/2mrv413.png
http://i60.tinypic.com/1zmju5l.png
kortsi
2015-06-30 AT 22:23
——
Yes, you do because osm2pgsql reports it is out of memory. It is
currently trying to use 4GB and that seems to be too much. If
you have 8GB of memory, try with 2048 and if that does not
work either with 1024. Also make sure you have a few dozen GB
of swap enabled.
——
in URL: http://localhost/nominatim/
i got map, but in top it showing error
Sarah
2015-08-13 AT 10:28
Al
2015-09-11 AT 08:29
We imported only some country (fr, uk, it, be, de, sp, it). To
process them we merged all les in a single one of 9 Go. It took 8
hours.
The import ran for about 36 hours and consumed 180 Go of
disk.
Best Regards
Al
gustavoDiniz
2015-09-28 AT 02:23
Return , BrazilRetornoBrazilbr
Hi,
Sebass
2015-10-03 AT 01:11
Freddy Taborda
2015-10-14 AT 05:50
ricarda
2016-02-17 AT 08:49
after
./utils/setup.php –create-website /var/www/html/nominatim
Tavito
2016-05-20 AT 15:55
Neha
2017-03-02 AT 10:49
Interspock
2018-08-18 AT 01:17
Andy
2016-04-10 AT 12:48
Sambhav
2016-05-06 AT 14:02
lieubv
2016-06-17 AT 10:17
Hi Kortsi.
This a best guide i ever read about Nominatim installation.
Even this time some changes need to be done that different
from what you said.
Anyway, i am enjoying it, that’s great.
Thank you so much.
David
2016-06-22 AT 10:25
Thanks!!
Andy
2016-10-19 AT 15:12
Thanks
Andy.
Andy W
2017-05-12 AT 16:30
jbx
2017-03-05 AT 12:53
Neha Sharma
2017-03-08 AT 08:41
Andy W
2017-05-12 AT 16:33
Thanks
Andy.
Pim
2017-10-20 AT 09:12
Hi guys,
We have been trying to setup a server for quite some time now
and are getting database errors every time. After the import
into Postgres (the last step) it’s an error every singl time.
kortsi
2017-10-20 AT 13:08