This document describes how to manually configure your system for running OpenStreetMap Carto. If you prefer quick, platform independent setup for a development environment, without the need to install and configure tools by hand, follow a Docker installation guide in DOCKER.md.
You need OpenStreetMap data loaded into a PostGIS database (see below for dependencies). These stylesheets expect a database generated with osm2pgsql using the flex backend.
Start by creating a database, we are using the database name gis
here:
sudo -u postgres createuser -s $USER
createdb gis
Enable PostGIS and hstore extensions with
psql -d gis -c 'CREATE EXTENSION postgis; CREATE EXTENSION hstore;'
Then, grab some OSM data; It's probably easiest to grab an PBF of OSM data from Geofabrik. Once you've done that, import with osm2pgsql:
osm2pgsql -O flex -S openstreetmap-carto-flex.lua -d gis ~/path/to/data.osm.pbf
You can find a more detailed guide to setting up a database and loading data with osm2pgsql at switch2osm.org.
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 gis -c 'ALTER SYSTEM SET jit=off;' -c 'SELECT pg_reload_conf();'
or any other means of adjusting the PostgreSQL config.
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 gis -f indexes.sql
The indexes can be created in parallel with
scripts/indexes.py -0 | xargs -0 -P0 -I{} psql -d gis -c "{}"
Some functions need to be loaded into the database for current versions. These can be added / re-loaded at any point using:
psql -d gis -f functions.sql
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
.
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
To display any map, a database containing OpenStreetMap data and some utilities are required:
- PostgreSQL
- PostGIS
osm2pgsql
>=1.8.0
to import your data into a PostGIS database- Python 3 with the
psycopg2
,pyyaml
, andrequests
libraries (python3-psycopg2
,python3-pyyaml
,python3-requests
packages on Debian-derived systems)python3 -m pip install --break-system-packages --user pyyaml requests psycopg2
ogr2ogr
for loading shapefiles into the database (gdal-bin
on Debian-derived systems)
- Kosmtik
- Install it:
git clone https://github.com/kosmtik/kosmtik cd kosmtik npm install
- The 0.0.17 release of Kosmtik wouldn't be enough because we need up-to-date CartoCSS and Mapnik versions.
- Launch it:
node index.js serve path/to/openstreetmap-carto/project.mml
- Install it:
- TileMill
- Not officially supported, but you may be able to use a recent TileMill version by copying or symlinking the project directly into your Mapbox/project directory.
Some colours, SVGs and other files are generated with helper scripts. Not all users will need these dependencies.
- Python
generate_road_colours.py
andgenerate_unpaved_patterns.py
depend on Color Math andnumpy
. To install these, run:python3 -m pip install --break-system-packages --user colormath numpy
CartoCSS and Mapnik are required for deployment.
With CartoCSS, these sources are compiled into a Mapnik compatible XML file. When running CartoCSS, specify the Mapnik API version you are using (at least 3.0.22: carto -a "3.0.22"
).