Skip to content

Example Deployment

PebblesFTW edited this page Aug 10, 2020 · 10 revisions

If you use a freshly installed system (see 1. System), you can use this as a line-by-line copy&paste guide, which will set up the complete project.
The comments are there to help you understand what the commands do.

1. System

The System used for this guide is a Virtual Machine running the Desktop version of Ubuntu 20.04 (64bit), normal installation with all system updates done (Ubuntu will prompt you to update your system after installation).

First of all, make sure your apt-get is up to date:

sudo apt-get update
sudo apt-get upgrade
reboot

2. Setup a Postgresql Database

2.1 Install Postgresql and Postgis

Add the Postgresql apt repository:

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt focal-pgdg main" >> /etc/apt/sources.list'

Replace focal with your Ubuntu version name, if you are using a different Ubuntu version.

wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt update

You can check if the versions are available for install with sudo apt-cache policy postgis and sudo apt-cache policy postgresql.

Install Postgres 12 and Postgis 3:

sudo apt-get install postgresql-12
sudo apt install postgis postgresql-12-postgis-3
sudo apt-get install libpq-dev

2.2 Setup Database

Create the database and connect to it:

sudo -u postgres psql
CREATE DATABASE testgis;
\connect testgis;

Create Extensions:

CREATE EXTENSION postgis;
CREATE EXTENSION hstore;

Create Schemas:

CREATE SCHEMA intermediate;
CREATE SCHEMA ohdm;
CREATE SCHEMA rendering;
CREATE SCHEMA mapnik;

Create User and grant priviliges:

CREATE USER mapnik WITH ENCRYPTED PASSWORD 'mapnik';

You can use a different password, of course.

GRANT ALL PRIVILEGES ON DATABASE testgis TO mapnik;
GRANT ALL PRIVILEGES ON SCHEMA intermediate TO mapnik;
GRANT ALL PRIVILEGES ON SCHEMA ohdm TO mapnik;
GRANT ALL PRIVILEGES ON SCHEMA rendering TO mapnik;
GRANT ALL PRIVILEGES ON SCHEMA mapnik TO mapnik;

Exit Database:

\q

Switch to installation directory:

Change into the directory you want Mapnik and Preselected Rendering to be installed in.

2.3 Insert data with OHDMConverter

Download the OHDMConverter and a JDBC driver:

mkdir ohdm && mkdir ohdm/converter && cd ohdm/converter
wget https://github.com/openhistoricaldatamap/osmimportupdate/releases/download/0.3/OSMImportUpdate.jar
wget https://github.com/openhistoricaldatamap/osmimportupdate/releases/download/0.3/postgresql-42.1.1.jar

Create config files for the OHDMConverter:

touch intermediate.txt rendering.txt ohdm.txt mapnik.txt
for i in *.txt; do echo -e 'servername:localhost\nportnumber:5432\nusername:mapnik\npwd:mapnik\ndbname:testgis\nschema:'${i%.*} > $i; done

Download a sample .osm file:

wget -O testmap.osm "https://api.openstreetmap.org/api/0.6/map?bbox=13.5165,52.4502,13.5502,52.4618"

You can replace the coordinates with anything you want, but a larger bounding box results in a longer conversion process.

This downloads map data from the current OpenStreetMap project. The OHDMConverter fills the valid_until column of your database with the current date. To test timesensitive rendering, you will need to edit the values in the columns valid_since and valid_until of the tables in the schema mapnik for certain objects to match your test case.

Install Java (at least Java 8):

sudo apt install default-jre

Should be a version greater than 8, check with java -version

Convert .osm into database:

java -classpath postgresql-42.1.1.jar -jar OSMImportUpdate.jar -o testmap.osm -i intermediate.txt
java -classpath postgresql-42.1.1.jar -jar OSMImportUpdate.jar -i intermediate.txt -d ohdm.txt
java -classpath postgresql-42.1.1.jar -jar OSMImportUpdate.jar -d ohdm.txt -r rendering.txt
java -classpath postgresql-42.1.1.jar -jar OSMImportUpdate.jar -r rendering.txt -m mapnik.txt

Change directory for the next steps:

cd ..

3. Setup Mapnik

If you don't have git, install it first:

sudo apt install git

3.1 Clone Mapnik

git clone -b 2.3.x https://github.com/mapnik/mapnik.git
cd mapnik

3.2 Install Mapnik dependencies

Install Python 2.7:

sudo apt install python2.7-dev
sudo apt-get install python-is-python2

Install Boost 1.67:

sudo apt-get install libboost1.67-all-dev

Install Proj:

sudo apt-get install libproj-dev

Install Freetype:

sudo apt-get install libfreetype6-dev

Install libxml2:

sudo apt-get install libxml2-dev

If the Server version of Ubuntu 20.04 is used, these libraries may be required as well:
sudo apt install g++ libicu-dev

3.3 Install Mapnik

./configure FREETYPE_INCLUDES=-I/usr/include/freetype2 FREETYPE_LIBS=-L/usr/lib/x86_64-linux-gnu PROJ_LIBS=-L/usr/lib/x86_64-linux-gnu PROJ_INCLUDES=-I/usr/include CUSTOM_DEFINES="-DACCEPT_USE_OF_DEPRECATED_PROJ_API_H=1"
make
sudo make install

3.4 Test Mapnik

make test

Since not every optional Mapnik dependency is installed, there are tests that will fail. This test is supposed to confirm that Mapnik works in general.

Change directory for the next steps:

cd ..

4. Setup Preselected Rendering

Clone Preselected Rendering:

git clone https://github.com/OpenHistoricalDataMap/Preselected-Rendering.git
cd Preselected-Rendering

4.1 Get world boundaries

Download the country borders and coastlines shapefiles:

Most likely the first three wget-commands will result in the error 429 Too Many Requests.
To get the files anyway copy the links into your preferred browser and download them there. Afterwards move them into the Preselected-Rendering directory manually. The commands for the .zip files however should work fine.

wget http://tile.openstreetmap.org/world_boundaries-spherical.tgz # (51M)
wget http://tile.openstreetmap.org/processed_p.tar.bz2 # (391M)
wget http://tile.openstreetmap.org/shoreline_300.tar.bz2 # (42M)
wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_populated_places.zip # (1.5 MB)
wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_boundary_lines_land.zip # (44 KB)

Extract the files:

tar -xzf world_boundaries-spherical.tgz
tar -xjf processed_p.tar.bz2 -C world_boundaries
tar -xjf shoreline_300.tar.bz2 -C world_boundaries
unzip ne_10m_populated_places.zip -d world_boundaries
unzip ne_110m_admin_0_boundary_lines_land.zip -d world_boundaries

Clean up the archives:

rm world_boundaries-spherical.tgz processed_p.tar.bz2 shoreline_300.tar.bz2 ne_10m_populated_places.zip ne_110m_admin_0_boundary_lines_land.zip

4.2 Install pip

The Package Installer for Python is needed for the database access.

Get the install file:

wget https://bootstrap.pypa.io/get-pip.py

Install pip:

sudo python get-pip.py

Remove install file:

rm get-pip.py

4.3 Install psycopg2

This is needed to access a postgres database in python.

sudo pip install psycopg2

4.4 Edit datasource settings

To access the database that was created in Step 2, the file inc/datasource-settings.xml.inc needs to be edited This can be done by opening it in your file explorer or within the terminal:

nano inc/datasource-settings.xml.inc

If the database was created precisely as stated in Step 2, your datasource settings should look something like this:

<Parameter name="type">postgis</Parameter>
<Parameter name="password">mapnik</Parameter>
<Parameter name="host">localhost</Parameter>
<Parameter name="port">5432</Parameter>
<Parameter name="user">mapnik</Parameter>
<Parameter name="dbname">testgis</Parameter>

<!-- this should be 'false' if you are manually providing the 'extent' -->
<Parameter name="estimate_extent">false</Parameter>
<!-- manually provided extent in epsg 900913 for whole globe -->
<!-- providing this speeds up Mapnik database queries -->
<Parameter name="extent">-20037508,-19929239,20037508,19929239</Parameter>

If you chose a more secure password, put that in the password parameter instead of mapnik.

4.5 Test Preselected Rendering

If you followed the instructions correctly, everything should be working now and you are ready to render an image:

python generate_image.py

If you changed the bounding box in Step 2.3, the bounding box in generate_image.py has to be changed accordingly.

This will output an image.png which you can open to check if the rendering was completed successfully.

Using generate_view_tiles.py

To read about how to preselect your rendering data, refer to the usage.