Skip to content

Instantly share code, notes, and snippets.

@boulderalf
Last active December 14, 2015 20:28
Show Gist options
  • Save boulderalf/5143732 to your computer and use it in GitHub Desktop.
Save boulderalf/5143732 to your computer and use it in GitHub Desktop.
Automated script for using Maperitive to create contours and hillshading and then uploading to MapBox using automated TileMill upload feature.
features
lines
contour major : contour[@isMulti(elevation, 100)]
contour minor : contour[@isMulti(elevation, 20) and not @isMulti(elevation, 100)]
properties
map-background-color : #F1EEE8
map-background-opacity : 0
font-weight : bold
font-family : Verdana
text-max-width : 7
text-halo-width : 25%
text-halo-opacity : 0.75
text-align-horizontal : center
text-align-vertical : center
font-stretch : 0.9
rules
target: contour*
define
line-color : #ffffff
line-opacity : 0.35
curved : true
if : *major
define
map.rendering.contour.label : true
min-zoom : 9
line-width : 11:0.1;11.9:1;12:2
font-size : 10
font-style : italic
font-weight : normal
text-halo-width : 35%
text-halo-opacity : 1
text-halo-color : #F1EEE8
else
define
min-zoom : 12
line-width : 1
draw : contour
features
lines
contour major : contour[@isMulti(elevation, 100)]
contour minor : contour[@isMulti(elevation, 20) and not @isMulti(elevation, 100)]
properties
map-background-color : #F1EEE8
map-background-opacity : 0
font-weight : bold
font-family : Verdana
text-max-width : 7
text-halo-width : 25%
text-halo-opacity : 0.75
text-align-horizontal : center
text-align-vertical : center
font-stretch : 0.9
rules
target: contour*
define
line-color : #7f3300
line-opacity : 0.35
curved : true
if : *major
define
map.rendering.contour.label : true
min-zoom : 9
line-width : 11:0.1;11.9:1;12:2
font-size : 10
font-style : italic
font-weight : normal
text-halo-width : 35%
text-halo-opacity : 1
text-halo-color : #F1EEE8
else
define
min-zoom : 12
line-width : 1
draw : contour
change-directory C:\ifactor\products\workspace\Virtual_Earth_Connector\MaperitiveCreateContours\blog
clear-map
set-setting name=map.decoration.grid value=False
set-geo-bounds -5.18793847256578,56.6581368928296,-4.90722891535273,56.7097180989809
generate-contours
use-ruleset location=contours.mrules as-alias=contours
export-bitmap file=cont.png
// use color-depth=32 so we can make use of the transparency in the ruleset
generate-mbtiles file=cont.mbtiles color-depth=32 minzoom=1 maxzoom=16
// we do not need to regenerate the contours. Simply apply a different styling.
use-ruleset location=contours-white.mrules as-alias=contours-white
apply-ruleset
export-bitmap file=cont-white.png
// use color-depth=32 so we can make use of the transparency in the ruleset
generate-mbtiles file=cont-white.mbtiles color-depth=32 minzoom=1 maxzoom=16
clear-map
set-setting name=map.decoration.grid value=False
set-geo-bounds -5.18793847256578,56.6581368928296,-4.90722891535273,56.7097180989809
generate-relief-igor
use-ruleset location=contours.mrules as-alias=contours
export-bitmap file=shading.png
// use color-depth=32 so we can make use of the transparency in the ruleset
generate-mbtiles file=shading.mbtiles color-depth=32 minzoom=1 maxzoom=16
set MAPERITIVE_EXE=C:/Maperitive/Maperitive.exe
:: make note of the original directory. That is where the MBTiles will be
set ORIG_DIR=%~dp0
:: first create the MBtiles
cmd %MAPERITIVE_EXE% %ORIG_DIR%contours.mscript
:: now upload the MBTiles to MapBox. The MapBox web form allows you to upload MBtile files
:: with max size of 5MB. If you want to upload larger files, you will need to use something
:: like TileMill's upload feature.
:: make sure that you are in the TileMill directory so we can use the appropriate node.exe
cd C:\Program Files (x86)\TileMill-v0.10.1\tilemill
:: see http://boulderalfmaps.blogspot.com/2013/01/tilemill-sync-info.html
:: for instructions about how to determine syncAccount and syncAccessToken
set SYNCACCOUNT=<syncAccount>
set SYNCACCESSTOKEN=<syncAccessToken>
:: upload the MBTiles file to your MapBox account.
:: you will need to specify your own <syncAccount> and <syncAccessToken> values
node index.js export cont %ORIG_DIR%cont.mbtiles --format=upload --syncAccount=%SYNCACCOUNT% --syncAccessToken=%SYNCACCESSTOKEN%
node index.js export cont-white %ORIG_DIR%cont-white.mbtiles --format=upload --syncAccount=%SYNCACCOUNT% --syncAccessToken=%SYNCACCESSTOKEN%
node index.js export shading %ORIG_DIR%shading.mbtiles --format=upload --syncAccount=%SYNCACCOUNT% --syncAccessToken=%SYNCACCESSTOKEN%
:: finally change back to the ORIG_DIR
cd %ORIG_DIR%
:: NOTE: MapBox makes use of the mbtile's (a sqlite file) metadata.name field to label the map
:: after it is uploaded. Maperitive always sets this field value to "My Map" so after uploading the
:: MBTiles to MapBox you will need to manually change the map name to something meaningful.
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment