Created
January 13, 2016 13:56
-
-
Save perrygeo/d4131f2ae9554462ee4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# tile_georef.sh | |
# | |
# Grab an mapbox ZYX tile and save as a geotiff with geoferencing | |
# tile_georef.sh 13 4168 3197 mapbox.satellite output.tif | |
# | |
set -u | |
z=$1 | |
x=$2 | |
y=$3 | |
tileset=${4:-mapbox.satellite} | |
output=${5:-output.tif} | |
tmp=$(mktemp -t tile).png | |
wget -O $tmp "http://a.tiles.mapbox.com/v4/$tileset/${z}/${x}/${y}@2x.png?access_token=$MAPBOX_ACCESS_TOKEN" | |
bounds=$(mercantile shapes "[$x, $y, $z]" --extents --mercator) | |
ulx=$(echo "$bounds" | cut -d " " -f1) | |
uly=$(echo "$bounds" | cut -d " " -f4) | |
lrx=$(echo "$bounds" | cut -d " " -f3) | |
lry=$(echo "$bounds" | cut -d " " -f2) | |
gdal_translate -a_ullr $ulx $uly $lrx $lry -a_srs epsg:3857 $tmp $output | |
rm $tmp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment