Installing Mapnik And OSM Bright

Installing Mapnik And OSM Bright

Mapnik is an open source mapping toolkit for desktop- and server-based map rendering, written in C++.

One of its many users is the OpenStreetMap project (OSM), which uses it in combination with an Apache Web Server module (mod_tile) to render tiles that make up the OSM ‘Slippy Map’ Layer.

For handling common software tasks such as memory management, file system access, regular expressions, and XML parsing, Mapnik utilizes the Boost C++ libraries.

Mapnik runs on Linux, OS X, Windows, and BSD systems.

There is also an osm2pgsql utility,[4] that converts OpenStreetMap data into a format that can be loaded into PostgreSQL. Mapnik can then be used to render the OSM data into maps with the appearance the user wants.

Install Mapnik library

Wait! Wait! Don’t insert the following commands blindly in the terminal.

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:

I insert the following commands as it is.

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/

 

What is SCons?

SCons is a software construction tool—that is, a superior alternative to the classic “Make” build tool that we all know and love.

SCons is implemented as a Python script and set of modules, and SCons “configuration files” are actually executed as Python scripts. This gives SCons many powerful capabilities not found in other software build tools.

After

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()

But, the command “import mapnik” was giving me the import error as shown below.

So, after travelling most of the streets of the map of my brain I installed mapnik through the following commands. 😉

sudo apt-get install pip

OR

sudo apt-get install python-pip

pip install mapnik

sudo apt-get install libmapnik-dev libmapnik3.0 mapnik-utils mapnik-vector-tile python-mapnik python3-mapnik

pip is a package management system used to install and manage software packages written in Python. Many packages can be found in the Python Package Index (PyPI)

Congratulations! if you have installed it.

Install mod_tile and renderd

 

mod_tile – A custom Apache module which is responsible for serving tiles and requests the rendering of tiles if they aren’t already available in cache or if they have changed since.

mod_tile uses Mapnik as a rendering backend.

 

Compile the mod_tile source code:

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

Download OSM Bright

screenshot

OSM Bright is a sensible starting point for quickly making beautiful maps based on an OpenStreetMap database. It is written in the Carto styling language and can be opened as a project in TileMill.

The style is still a work in progress and you are encouraged to use the issue tracker to note missing features or problems with the current implementation.

OSM Bright depends on two large shapefiles. You will need to download and extract them before continuing.

Download them to the shp directory in the osm-bright folder. You can do this with wget like:

To begin with, we need to download both the OSM Bright stylesheet, and also the additional data resources it uses (for coastlines and the like).  Again, substitute your username for username in the “chown” command below.

sudo mkdir -p /usr/local/share/maps/style
sudo chown username /usr/local/share/maps/style
cd /usr/local/share/maps/style
wget https://github.com/mapbox/osm-bright/archive/master.zip
wget http://data.openstreetmapdata.com/simplified-land-polygons-complete-3857.zip
wget http://data.openstreetmapdata.com/land-polygons-split-3857.zip
mkdir ne_10m_populated_places_simple
cd ne_10m_populated_places_simple
wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_populated_places_simple.zip
unzip ne_10m_populated_places_simple.zip
rm ne_10m_populated_places_simple.zip
cd ..

We then move the downloaded data into the osm-bright-master project directory:

unzip '*.zip'
mkdir osm-bright-master/shp
mv land-polygons-split-3857 osm-bright-master/shp/
mv simplified-land-polygons-complete-3857 osm-bright-master/shp/
mv ne_10m_populated_places_simple osm-bright-master/shp/

 

To improve performance, we create index files for the larger shapefiles:

cd osm-bright-master/shp/land-polygons-split-3857
shapeindex land_polygons.shp
cd ../simplified-land-polygons-complete-3857/
shapeindex simplified_land_polygons.shp
cd ../..

Configuring OSM Bright

The OSM Bright stylesheet now needs to be adjusted to include the location of our data files. Edit the file osm-bright/osm-bright.osm2pgsql.mml in your favourite text editor, for example:

gedit osm-bright/osm-bright.osm2pgsql.mml

Find the lines with URLs pointing to shapefiles (ending .zip) and replace each one with these appropriate pairs of lines:

"file": "/usr/local/share/maps/style/osm-bright-master/shp/land-polygons-split-3857/land_polygons.shp", 
"type": "shape"
"file": "/usr/local/share/maps/style/osm-bright-master/shp/simplified-land-polygons-complete-3857/simplified_land_polygons.shp", 
"type": "shape",
"file": "/usr/local/share/maps/style/osm-bright-master/shp/ne_10m_populated_places_simple/ne_10m_populated_places_simple.shp", 
"type": "shape"

Note that we are also adding “type”: “shape” to each one. (If you’re using nano, to save, now press ctrl-X and Y.)

Finally, in the section dealing with “ne_places”, replace the “srs” and “srs-name” lines with this one line:

"srs": "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"

You have configured OSM Bright.

Stay tuned. 🙂

Advertisements

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