Skip to content

Instantly share code, notes, and snippets.

@nebulon42
Last active August 26, 2016 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nebulon42/e5f73e511d44726ef66c7e13eb9e3eca to your computer and use it in GitHub Desktop.
Save nebulon42/e5f73e511d44726ef66c7e13eb9e3eca to your computer and use it in GitHub Desktop.
openstreetmap-carto developer setup

openstreetmap-carto Developer Setup

  • data: PostgreSQL + PostGIS, osm2pgsql for importing into the database; and OSM data extract
  • code: openstreetmap-carto (+ Git, Python)
  • editing software: Kosmtik (+ Node.js)

Preparation

openstreetmap-carto

  • create a folder for openstreetmap-carto and change into the directory on the command line (or Git-Bash)
  • Click "Clone or download" at the GitHub-Repository and select "Use HTTPS"
  • copy the URL
  • execute git clone <copied URL> . (code will be checked out in current directory)
  • execute ./get-shapefiles.sh or ./get-shapefiles.py (whatever exists)

Database

  • create a database (name e.g. osm)
  • activate PostGIS: CREATE EXTENSION postgis;
  • opt. activate HStore: CREATE EXTENSION hstore;
  • import data (Linux):
sudo -u postgres osm2pgsql --create --slim --cache CACHE --number-processes NUM --hstore --style path/to/openstreetmap-carto/openstreetmap-carto.style --multi-geometry --database osm --username postgres path/to/extract.pbf

CACHE = size of RAM - memory in use - X (do not choose a size too big as swapping might become necessary then [slow])

NUM = number of CPU cores

Importing can take quite some time depending on the size of the data extract!

Install Kosmtik

  • Click "Clone or download" at the GitHub-Repository and select "Download ZIP" (or use the method like for osm-carto above)
  • extract the ZIP-file in a directory
  • execute npm install in this directory (needs Node.js)

Configure and start Kosmtik

  • create a local config file, e.g. osm.localconfig:
exports.LocalConfig = function (localizer, project) {
localizer.where('center').then([13.0463, 47.7978, 15]); // Salzburg
localizer.where('Layer').if({'Datasource.type': 'postgis'}).then({
	"Datasource.dbname": "osm",
	"Datasource.password": "postgres",
	"Datasource.user": "postgres",
	"Datasource.host": "localhost"
});
// You can also do it in pure JS
project.mml.bounds = [1, 2, 3, 4];
};
  • start Kosmtik:
node index.js serve --localconfig path/to/osm.localconfig path/to/openstreetmap-carto/project.yaml

edit osm-carto

  • use your own text editor e.g. Atom, gedit, TextWrangler, Notepad++
  • change the *.mss files
  • view the changes in Kosmtik
  • if you change the layer definitions in project.yaml you have to execute ./yaml2mml.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment