Manually Building your Own Tile Server With OSM
Yogesh K S IT for Change
What is a Tile server?
Tiles are square map images that are placed together to make a map on the web.
A tile server draws (renders) these images from a map database.
3rd party provider vs own tile server
What you want?! -- Depends on your requirements
3rd party tiles Own tiles
Easier to get started Difficult to set up
Lesser control Full control
Paid plans Hardware resources
Serving your own tiles with OSM Data
OpenStreetMap tile server
The OSM tile server stack has five main components
1. Mod_tile
2. Renderd
3. Mapnik
4. Osm2pgsql
5. Postgis
Building Tile server on Ubuntu GNU/Linux 16.04
Packages to build these components: sudo apt install libboost-all-dev 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 libtiff5-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
Installing postgresql/postgis
Installed via the Ubuntu package manager sudo apt install postgresql postgresql-contrib postgis postgresql-9.5-postgis-2.2
Setup postgresql/postgis
* Create database
* Create user
* Add extensions – postgis, hstore
Install osm2pgsql from source
Get the source from github: git clone git://github.com/openstreetmap/osm2pgsql.git
Get into osm2pgsql directory: cd osm2pgsql
Build and install: mkdir build && cd build cmake .. make sudo make install
Mapnik
Install Mapnik from Ubuntu package manager sudo apt-get install autoconf apache2-dev libtool libxml2-dev libbz2-dev libgeos-dev libgeos++-dev libproj-dev gdal-bin libgdal1-dev libmapnik-dev mapnik-utils python-mapnik
Check mapnik python >>> import mapnik >>>
mod_tile and renderd
Install mod_tile and renderd from source git clone git://github.com/SomeoneElseOSM/mod_tile.git cd mod_tile ./autogen.sh ./configure make sudo make install sudo make install-mod_tile
Stylesheet configuration
Stylesheet controls representation of map data in tiles. Standard style on osm.org is “OpenStreetMap Carto”
Get it from github: git clone git://github.com/gravitystorm/openstreetmap- carto.git cd openstreetmap-carto sudo apt install npm nodejs-legacy sudo npm install -g carto convert the carto to mapnik: carto project.mml > mapnik.xml
Loading Data
Get data extracts from Geofabrik mkdir ~/data cd ~/data wget http://download.geofabrik.de/asia/india-latest.osm.pbf
Load it database with osm2pgsql osm2pgsql -d gis --create --slim -G --hstore --tag-transform- script ~/openstreetmap-carto/openstreetmap-carto.lua -C 2500 --number-processes 1 -S ~/openstreetmap- carto/openstreetmap-carto.style ~/data/india- latest.osm.pbf
Low zoom country boundaries and fonts
Use python script within openstreetmap-carto cd ~/openstreetmap-carto/ scripts/get-shapefiles.py
Fonts for non-latin, unicode characters sudo apt-get install fonts-noto-cjk fonts-noto-hinted fonts- noto-unhinted ttf-unifont
Setting up your webserver
Configure renderd sudo nano /usr/local/etc/renderd.conf num_threads=4 XML=/home/renderaccount/src/openstreetmap- carto/mapnik.xml URI=/india/
Run and check for errors renderd -f -c /usr/local/etc/renderd.conf
Run in background as “systemd” service sudo systemctl enable renderd
Configure Apache
Tell Apache about mod_tile here: sudo nano /etc/apache2/conf-available/mod_tile.conf
Tell Apache about renderd here: sudo nano /etc/apache2/sites-available/000-default.conf sudo service apache2 reload
Viewing tiles
See the lowest zoom level tile here: http://yourserveripaddress/india/0/0/0.png
Using tiles:
* OpenLayers - http://openlayers.org/ * Leaflet - http://leafletjs.com/
Thank you!
Photos under CC-BY-SA https://switch2osm.org/