Last active
January 4, 2020 01:33
-
-
Save skyqrose/b3d44233665db988c0fc127c59ddd6a4 to your computer and use it in GitHub Desktop.
Download map tiles from a tile server and stitch them together into a single image. An alternative to taking a screenshot of google maps.
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
# Download map tiles from a tile server and stitch them together into a single image | |
# An alternative to taking a screenshot of google maps | |
# Edit the settings below and then run ./map-download.sh | |
# To find the z, x, and y coordinates that you want, this tool might be useful: | |
# https://github.com/skyqrose/coordinates-tile-server | |
# Requires ImageMagick's convert command to assemble the images | |
# Note that ImageMagick has security vulnerabilities when working with untrusted files | |
# So there's some risk to using this with untrusted tileservers | |
# Map settings | |
URL="https://a.tile.openstreetmap.org/{z}/{x}/{y}.png" | |
ZOOM=14 | |
STARTX=4957 | |
ENDX=4958 | |
STARTY=6059 | |
ENDY=6060 | |
# Where files will be downloaded to and combined | |
# Downloads to filenames based on the coordinates $x or $x-$y, e.g. 4957 or 4957-6059 | |
# So don't run this where similarly named files might be overwritten | |
DIRECTORY=. | |
OUTPUTFILE=out | |
cd $DIRECTORY\ | |
|| { echo "directory $DIRECTORY does not exist"; exit 1; } | |
z=$ZOOM | |
xs=$(seq $STARTX $ENDX) | |
ys=$(seq $STARTY $ENDY) | |
for x in $xs | |
do | |
colfiles= | |
for y in $ys | |
do | |
url=$URL | |
url=${url//\{z\}/$z} | |
url=${url//\{x\}/$x} | |
url=${url//\{y\}/$y} | |
echo wget -q -O $x-$y $url | |
wget -q -O $x-$y $url\ | |
|| { echo "failed to fetch tile $url"; exit 2; } | |
colfiles="$colfiles $x-$y" | |
done | |
echo convert $colfiles -append $x | |
convert $colfiles -append $x\ | |
|| { echo "failed to join column at x=$x"; exit 3; } | |
echo rm $colfiles | |
rm $colfiles | |
done | |
echo convert $xs +append $OUTPUTFILE | |
convert $xs +append $OUTPUTFILE\ | |
|| { echo "failed to join columns together"; exit 4; } | |
echo rm $xs | |
rm $xs | |
echo done. output is at $DIRECTORY/$OUTPUTFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment