Tuesday, March 12, 2013

Automating Maperitive generation and MapBox upload

I recently blogged about integrating MapBox maps within the Smallworld GIS.  I included a video clip that showed how I connected Smallworld to contour and hillshading maps hosted on MapBox.  Those contour and hillshaded maps were created using Maperitive.  In this post, I want to share how I automated the generation and upload of these maps.

If you are familiar with Maperitive you will know that it has had a scripting language for a long time and recently it also introduced Python scripting.  For this post I am still using the old scripting framework.  I imagine it can easily be ported to Python.

The Maperitive script references some custom rulesets that I created to allow me to explicitly style the contour lines.  Following is the code I used to automate map generation and upload.

  • contours-white.mrules
    • a Maperitive ruleset styling white contour lines with transparent background
  • contours.mrules
    • a Maperitive ruleset styling brown contour lines with transparent background
  • contours.mscript
    • the Maperitive commands required to generate brown contours, white contours and hillshading.  Note that color-depth=32.  This is required to allow transparent backgrounds in the tiles stored in the MBtiles database
  • create_and_upload.bat

Tuesday, January 15, 2013


In my previous post, I described the steps required to automate a TileMill project for rendering and then uploading an MBTiles file to MapBox.

The one important part that was not covered in the post was the authentication method.

As part of the TileMill upload process, you are required to set --syncAccount and --syncAccessToken parameters.  This information is discoverable if you dig deep into TileMill caches.  To make it more easily accessible I created a TileMill plugin called tilemill-sync-info.  It simply exposes your sync information on the Application Settings page...

Now you can copy/paste that information into your batch upload scripts.

Productivity Tip: I use TileMill for both work and personal projects and host these projects on separate work and personal MapBox accounts.  To keep from having to constantly reauthorize TileMill between these two accounts prior to upload, I simply create batch upload scripts for each TileMill project with account-specific upload credentials.  Then I can author my projects in TileMill and when I am ready to upload to MapBox I simply run the appropriate project upload script and it sends my new map to the correct account.

I was inspired to create a TileMill plugin based on @willwhitedc's MapBox presentation at JS.Geo13 (#jsgeo13)