-
Notifications
You must be signed in to change notification settings - Fork 169
/
create-tiles.sh
executable file
·36 lines (28 loc) · 951 Bytes
/
create-tiles.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bash
# Original Source: https://github.com/mapbox/gdal-polygonize-test
set -eu
raster=$1
xtiles=$2
ytiles=$3
# get raster bounds
ul=($(gdalinfo $raster | grep '^Upper Left' | sed -e 's/[a-zA-Z ]*(//' -e 's/).*//' -e 's/,/ /'))
lr=($(gdalinfo $raster | grep '^Lower Right' | sed -e 's/[a-zA-Z ]*(//' -e 's/).*//' -e 's/,/ /'))
xmin=${ul[0]}
xsize=$(echo "${lr[0]} - $xmin" | bc)
ysize=$(echo "${ul[1]} - ${lr[1]}" | bc)
xdif=$(echo "$xsize/$xtiles" | bc -l)
for x in $(eval echo {0..$(($xtiles-1))}); do
xmax=$(echo "$xmin + $xdif" | bc)
ymax=${ul[1]}
ydif=$(echo "$ysize/$ytiles" | bc -l)
for y in $(eval echo {0..$((ytiles-1))}); do
ymin=$(echo "$ymax - $ydif" | bc)
# Create chunk of source raster
gdal_translate -q \
-projwin $xmin $ymax $xmax $ymin \
-of GTiff \
$raster ${raster%.tif}_${x}_${y}.tif
ymax=$ymin
done
xmin=$xmax
done