Generate mbtiles – node.js & mapnik


Usually to generate mbtiles we do require some 3rd party software, however there is one method which at the end does require only one command to be executed and we can create mbtiles from any compatible services.

Example:

Let’s say we need a map for Lake District UK and we would like to use OpenTopoMap as our base-map.

OpenTopoMap – Lake District UK

OpenTopoMap – Lake District UK

 

Bboxfinder

Bboxfinder

  • Just copy the extent of the box – in our case it will be:-3.395462,54.355356,-2.619553,54.678992
  • Remove the comas from it so it looks like:-3.395462 54.355356 -2.619553 54.678992
  • Now you need to build the node.js command this will look like:

    tl copy -z 0 -Z 15 -b “-3.395462 54.355356 -2.619553 54.678992” “http://api.mapbox.com/v4/mapbox.outdoors/{z}/{x}/{y}.png” mbtiles://./lake-district.mbtiles

  • When you execute the command the tiles will be downloaded and lake-district.mbtiles file will be saved in C:\Users\{your_user_name}\ folder.

 

Easy and effortless, but how to get there?

  1. Download and install node.js from https://nodejs.org/download/  – make sure it’s 32Bit version otherwise mapnik will not work.
  2. Install Python if you do not have it already.
  3. Install mapnik executing command in the node.js console:

    npm install -g tl mbtiles tilelive-http

  4. You should get the screen like bellow after successful install:

    Node.js – mapnik installation

    Node.js – mapnik installation

  5. You can try to create test mbtiles file for Tatra mountains:

    tl copy -z 0 -Z 15 -b “19.481506 49.050920 20.407791 49.319751” “http://a.tile.openstreetmap.org/{z}/{x}/{y}.png” mbtiles://./tatra.mbtiles

     

As you can see there is a bit of config work required but ones it’s done it’s done and the generation of the tiles is very quick.

Leave a Reply