Skip to content

Instantly share code, notes, and snippets.

Last active April 12, 2017 09:25
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Bash script to batch export Tilemill projects
#This script generates one export for each year of a Tilemill project to mbtiles format
#Run using 'bash [project-name]'
#For more info:
# - stylesheet = style.mss
# - selector = year
#Make sure the field separator is a ','
#Check if a project has been specified
if [ -z $project ]; then
echo You haven\'t specified a project, please specify one by using: bash \[project\]
for year in $range
#Change the selector to the year we want to export
sed -i -r -e 's/ano=2[0-9]{3}/ano='$year'/g' ~/Documents/MapBox/project/$project/style.mss
#Change the project name and description to include indication of year
sed -i -r -e 's/\"name\": \"Occurrences\"/\"name\": \"Occurrences '$year'\"/g' ~/Documents/MapBox/project/$project/project.mml
sed -i -r -e 's/\"description\": \"Occurrences per area\"/\"description\": \"Occurrences per area '$year'\"/g' ~/Documents/MapBox/project/$project/project.mml
#Do the actual export
/usr/share/tilemill/index.js export $project ~/Documents/$project-$year.mbtiles --bbox='-10.2063,36.5361,-5.8557,42.4640' --format=mbtiles --minzoom=4 --maxzoom=13 --metatile=2
#and upload it. On project we have to specify a unique name, otherwise MapBox will just overwrite the project each time you upload
/usr/share/tilemill/index.js export $project-$year ~/Documents/$project-$year.mbtiles --format=upload --syncAccount="" --syncAccessToken=""
#Change the project name and description back to original
sed -i -r -e 's/\"name\": \"Occurrences [0-9]{4}\"/\"name\": \"Occurrences\"/g' ~/Documents/MapBox/project/$project/project.mml
sed -i -r -e 's/\"description\": \"Occurrences per admin area [0-9]{4}\"/\"description\": \"Occurrences per admin area\"/g' ~/Documents/MapBox/project/$project/project.mml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment