Skip to content

Instantly share code, notes, and snippets.

@almereyda
Created September 5, 2012 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save almereyda/3646127 to your computer and use it in GitHub Desktop.
Save almereyda/3646127 to your computer and use it in GitHub Desktop.
Get & Merge WMS Tiles into one Image
#! /bin/bash
if [ $# -lt 5 ]; then
echo "Usage: zoom topleft_x topleft_y bottomright_x bottomright_y"
exit
fi
#echo -n "Herunterladen der watercolor tiles für die gaka, zoomstufe: "
ZOOM=$1
#read -e ZOOM
echo -n "Zoomstufe ist $ZOOM/n"
TOPX=$2
echo -n "topleft_x: $TOPX/n"
#read -e TOPX
TOPY=$3
echo -n "topleft_y: $TOPY/n"
#read -e TOPY
BOTTOMX=$4
echo -n "bottomright_x: $BOTTOMX/n"
#read -e BOTTOMX
BOTTOMY=$5
echo -n "bottomright_y: $BOTTOMY/n"
#read -e BOTTOMY
let DELTAX=BOTTOMX-TOPX
echo "deltax ist $DELTAX"
let DELTAY=BOTTOMY-TOPY
echo "deltay ist $DELTAY"
if [ ! -d "$ZOOM" ]; then
mkdir $ZOOM
fi
cd $ZOOM
for i in `seq 0 $DELTAX`
do
let X=TOPX+i
if [ ! -d "$X" ]; then
mkdir $X
fi
cd $X
for j in `seq 0 $DELTAY`
do
let Y=TOPY+j
echo "$ZOOM / $X / $Y"
if [ ! -f "$Y.jpg" ]; then
wget http://a.tile.stamen.com/watercolor/`printf $ZOOM`/`printf $X`/`printf $Y`.jpg
else
echo "Tile $ZOOM/$X/$Y ist schon gespeichert."
fi
done
cd ..
done
cd ..
echo fertig.
### Merge tiles into one image ###
import sys, os
print "Usage: tile_merge.py zoomlevel xMin xMax yMin yMax filename"
print
print "This utility merges tiles."
zoom = None
xMin, xMax, yMin, yMax = None, None, None, None
filename = None
argv = sys.argv
i = 1
while i < len(argv):
arg = argv[i]
if zoom is None:
zoom = int(argv[i])
elif xMin is None:
xMin = int(argv[i])
elif xMax is None:
xMax = int(argv[i])
elif yMin is None:
yMin = int(argv[i])
elif yMax is None:
yMax = int(argv[i])
elif filename is None:
filename = argv[i]
else:
Usage("ERROR: Too many parameters")
i = i + 1
import Image
tileSize = 256
tileDir = os.path.join(os.curdir,"tiles",str(zoom))
out = Image.new( 'RGB', ( (xMax - xMin + 1) * tileSize, (yMax - yMin + 1) * tileSize) )
imx = 0
for x in range(xMin, xMax+1):
imy = 0
for y in range(yMin, yMax+1):
tileFile = os.path.join(tileDir,str(x),str(y)+".jpg")
tile = Image.open(tileFile)
out.paste( tile, (imx, imy) )
imy += tileSize
imx += tileSize
out.save(os.path.join(os.curdir,filename))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment