Skip to content

Latest commit

 

History

History
233 lines (141 loc) · 6.97 KB

README.md

File metadata and controls

233 lines (141 loc) · 6.97 KB

Mapnik OpenStreetMap styles

This repo contain mapnik and CartoCSS OpenStreetMap stylesfor the Mapnik renderer.

Prerequisites

Install system dependencies and packages

sudo apt update
sudo apt install wget curl
sudo apt install git git-lfs
sudo apt install python3 python3-pip python3-venv
sudo apt install postgresql-16 postgresql-postgis gdal-bin osm2pgsql

curl -fsSL https://deb.nodesource.com/setup_22.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt install nodejs
sudo npm install -g carto

Create system user

Make sure to add your user to the oklab-group.

sudo adduser oklab
sudo usermod -a -G www-data oklab
sudo mkdir -p /opt/oklab
sudo chown -R oklab:oklab /opt/oklab
sudo chmod 770 -R /opt/oklab

Prepare database

Open and edit /etc/postgresql/16/main/pg_hba.conf add following two entries into your config.

local   oklab           oklab                                   trust
host    oklab           oklab           127.0.0.1/32            trust

After these edits run sudo systemctl restart postgresql.service. To verify everything works run..

sudo systemctl status postgresql.service

Now change user sudo -i -u postgres and run these commands.

createuser -d oklab
createdb -O oklab oklab
psql -U oklab
exit

Note since the oklab-user does not have superuser permissions you must login with psql -U postgres

\c oklab
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE EXTENSION IF NOT EXISTS hstore;
ALTER TABLE geometry_columns OWNER TO oklab;
ALTER TABLE spatial_ref_sys OWNER TO oklab;
exit

Download OSM extracts

To use TileMill locally we need OpenStreetMap extracts. You can use Geofabrik to choose a suitable extract. Take care that you are logged in as oklab user, if not switch your user like sudo -i -u oklab.

mkdir -p /opt/oklab/map
cd /opt/oklab/map
wget https://download.geofabrik.de/europe/germany/<geofabrik-download-filename>

Clone OSM carto

Before we are ready to start we want to clone the main OpenStreetMap carto project. Take care that you are logged in as oklab user, if not switch your user like sudo -i -u oklab.

mkdir -p /opt/oklab/git
cd /opt/oklab/git
git clone https://github.com/gravitystorm/openstreetmap-carto.git

Import OSM extracts

Once you cloned the repository you are ready to import the OpenStreetMap extract. Make sure to replace <geofabrik-download-filename> with the filename you downloaded before. Take care that you are logged in as oklab user, if not switch your user like sudo -i -u oklab.

mkdir -p /opt/oklab/git
cd /opt/git/openstreetmap-carto
osm2pgsql -O flex -S openstreetmap-carto-flex.lua -d oklab /opt/oklab/map/<geofabrik-download-filename>

Disable JIT

We do not recommend PostgreSQL JIT, which is on by default in PostgreSQL 12 and higher. JIT is benifitial for slow queries where executing the SQL takes substantial time and that time is not spent in function calls. This is not the case for rendering, where most time is spent either fetching from disk, in PostGIS functions, or the query is fast. In theory, the query planner will only use JIT on slower queries, but it is known to get the type of queries map rendering requires wrong.

Disabling JIT is essential for use with Kosmtik and other style development tools.

JIT can be disabled with psql -d oklab -c 'ALTER SYSTEM SET jit=off;' -c 'SELECT pg_reload_conf();' or any other means of adjusting the PostgreSQL config.

Custom indexes

Custom indexes are required for rendering performance and are essential on full planet databases. These are generated by the scripts/indexes.py script, see scripts/indexes.py --help for various advanced options, but the command below will work to create the indexes on a new installation:

psql -d oklab -f indexes.sql

The indexes can be created in parallel with

scripts/indexes.py -0 | xargs -0 -P0 -I{} psql -d oklab -c "{}"

Database functions

Some functions need to be loaded into the database for current versions. These can be added / re-loaded at any point using:

psql -d oklab -f functions.sql

Scripted download

Some features are rendered using preprocessed shapefiles.

To download them and import them into the database you can run the following script:

scripts/get-external-data.py

The script downloads shapefiles, loads them into the database, and sets up the tables for rendering. Additional script options and corresponding documentation is available by invoking scripts/get-external-data.py --help.

Download fonts

The stylesheet uses Noto, an openly licensed font family from Google with support for multiple scripts. The stylesheet uses Noto's "Sans" style where available. If not available, this stylesheet uses another appropriate style from the Noto family. The "UI" version is used where available, as its vertical metrics fit better with Latin text.

Hanazono is used a fallback for seldom used CJK characters that are not covered by Noto.

For more details, see the documentation at fonts.mss.

To download the fonts, run the following script

scripts/get-fonts.sh

Setup TileMill

To locally develop, test or create new carto styles with TileMill, you need to have a specific Node version installed on you machine. Take care that you are logged in as oklab user, if not switch your user like sudo -i -u oklab. The following step can be done in any directory.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
nvm install lts/carbon
nvm use v8.17.0

Now make sure to clone the TileMill project from GitHub as oklab user and run setup.

cd /opt/oklab/git
git clone https://github.com/tilemill-project/tilemill.git
cd tilemill
npm install
npm start

Install fonts

Get Noto Emoji Regular font, despite it being deprecated by Google and for some reason this one is missing in the default packages

wget https://github.com/googlefonts/noto-emoji/blob/9a5261d871451f9b5183c93483cbd68ed916b1e9/fonts/NotoEmoji-Regular.ttf?raw=true --content-disposition -P /usr/share/fonts/
wget https://github.com/stamen/terrain-classic/blob/master/fonts/unifont-Medium.ttf?raw=true --content-disposition -P /usr/share/fonts/

Running TileMill

This section needs to be extended. But here are some basic PostGIS layer configurations.

Connection string

dbname=oklab host=127.0.0.1 port=5432 user=oklab

Projection string, as reference you may have a look at https://epsg.io/3857

+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over

How to Contribute

Contributions are welcome! Please refer to the CONTRIBUTING.md guide for details on how to get involved.


License

This repository is licensed under CC0-1.0.