Open Street Map (OSM)

OpenStreetMap (OSM) is a collaborative project to create a free editable map of the world. Two major driving forces behind the establishment and growth of OSM have been restrictions on use or availability of map information across much of the world and the advent of inexpensive portable satellite navigation devices. OSM is considered a prominent example of volunteered geographic information.

Few days ago, I installed my OSM tile server on my local computer. Here, I’m sharing the tutorials I followed and I’m also writing my own experiences, I got while going with all this procedure.

Tutorials I followed:

  1. Manually Building a Tile Server (From source)
  2. Using Packages

I followed both the procedure one by one and tried to understand how its working. At the end, I took help from both the sides for quick working. I am sharing the procedure with little explanation here.

Steps I followed and problems I faced:

As we know, the OSM tile server stack is a collection of programs and libraries that work together to create a time server. There are many ways to achieve this goal but here, the description of most standard version that is also used on the main OpenStreetMap.org tile server is given in both the tutorials.

OSM tile server consists of 5 main components:

  1. Mod_tile
  2. Rendered: Rendered provides a priority queuing system for rendering requests to manage and smooth out the load from rendering requests.
  3. Mapnik
  4. osm2pgsql
  5. postgresql/postgis database

So, in order to build the above components, first I installed the given dependencies as you can see in the tutorial.

 sudo apt-get install libboost-all-dev subversion git-core
 tar unzip wget bzip2 build-essential autoconf libtool libxml2-dev
 libgeos-dev libgeos++-dev libpq-dev libbz2-dev libproj-dev munin-node
 munin libprotobuf-c0-dev protobuf-c-compiler libfreetype6-dev
 libpng12-dev libtiff4-dev libicu-dev libgdal-dev libcairo-dev
 libcairomm-1.0-dev apache2 apache2-dev libagg-dev liblua5.2-dev
 ttf-unifont lua5.1 liblua5.1-dev libgeotiff-epsg node-carto

After this, I followed the whole procedure as given in tutorial 1 up to the installation of mod_tile without any error or any problem. Here, I’m still re-writing those steps for your convenience.

Installing postgresql/postgis

On Ubuntu there are pre-packaged versions of both postgis and postgresql, so these can simply be installed via the Ubuntu package manager.

sudo apt-get install postgresql postgresql-contrib postgis
postgresql-9.3-postgis-2.1

Now you need to create a postgis database. The defaults of various programs assume the database is called gis and we will use the same convention in this tutorial, although this is not necessary. Substitute your username for username in the two places below. This should be the username that will render maps with Mapnik.

sudo -u postgres -i
createuser username # answer yes for superuser (isn't strictly necessary)
createdb -E UTF8 -O username gis
exit

Create a Unix user for this user, too, choosing a password when prompted:

sudo useradd -m username
sudo passwd username

Set up PostGIS on the PostgreSQL database (again, substitute your username for username below):

sudo -u postgres psql
\c gis
CREATE EXTENSION postgis;
ALTER TABLE geometry_columns OWNER TO username;
ALTER TABLE spatial_ref_sys OWNER TO username;
\q
exit

You may also need to edit other tables like, ‘planet_osm_line’, ‘planet_osm_nodes’, ‘planet_osm_point’, ‘planet_osm_rels’, ‘planet_osm_roads’, ‘planet_osm_ways’, ‘planet_osm_polygon’, etc. when you’ll install osm2pgsql and run a script ./install-postgis-osm-user.sh

<q>osm2pgsql creates two sets of tables. 1) The rendering tables “planet_osm_point” “planet_osm_line” “planet_osm_roads” and “planet_osm_polygon” and 2) the “slim mode” tables “planet_osm_nodes” “planet_osm_ways” and “planet_osm_rels”.

For rendering, only the rendering tables are needed. These contain a lossy (not all tags and data are needed), transformed ( using postgis geometries rather than OSM nodes and ways) version of the OSM data optimised for rendering.

In the slim mode tables on the other hand, the (more or less) original OSM data is stored. This is necessary during the initial import if you don’t have enough memory to store everything in RAM and for updating the data with the diff files. It is however not necessary for rendering with renderd.</q>

Installing osm2pgsql

osm2pgsql is under active development and is best compiled from source.

mkdir ~/src
cd ~/src
git clone git://github.com/openstreetmap/osm2pgsql.git
cd osm2pgsql
./autogen.sh
./configure
make
sudo make install

Install Mapnik library

Next, we need to install the Mapnik library. Mapnik is used to render the OpenStreetMap data into the tiles used for an OpenLayers web map.

Build the Mapnik library from source:

cd ~/src
git clone git://github.com/mapnik/mapnik
cd mapnik
git branch 2.2 origin/2.2.x
git checkout 2.2

python scons/scons.py configure INPUT_PLUGINS=all OPTIMIZATION=3 
SYSTEM_FONTS=/usr/share/fonts/truetype/

make
sudo make install
sudo ldconfig

When you will install mapnik, on applying make, it give you notice like this

Notice: dependencies not met for plugin ‘occi’, not building…
Notice: dependencies not met for plugin ‘rasterlite’, not building…

don’t be panik. You may ignore this.

Verify that Mapnik has been installed correctly:

python
>>> import mapnik
>>>

If python replies with the second chevron prompt >>> and without errors, then Mapnik library was found by Python. Congratulations! You can leave Python with this command:

>>> quit()

Install mod_tile and renderd

Compile the mod_tile source code:

cd ~/src
git clone git://github.com/openstreetmap/mod_tile.git
cd mod_tile
./autogen.sh
./configure
make
sudo make install
sudo make install-mod_tile
sudo ldconfig

Then the actual work started,

Stylesheet Configuration:

I will share about this in my next post.

Advertisements

Published by

kaurdavinder

I am the one who discover myself daily through reading, writing, interacting with people and expressing my thoughts to inspire them if I would be able to bring a little change to the society through my work. I write blogs, participate in various social activities and want to be a Professional Speaker. Currently, I am pursuing my post graduation in Computer Applications from Guru Nanak Dev Engineering College, Ludhiana and I’m very much active in many technical & social communities.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s