Download Tile Map

Mar 8, 2017

Tile Map

Peta yang ada di Web sekarang ini banyak menggunakan tile map. Tile map menampilkan peta memakai gambar-gambar kecil dalam grid berbentuk persegi. Gambar yang diunduh sesuai dengan luas yang sedang dilihat pada level zoom, bujur maupun lintang tersebut. Gambar-gambar kecil tersebut biasanya berformat PNG karena memiliki ketajaman yang lebih baik dibandingkan format JPEG terutama pada garis dan batas antara dua warna.

Pada umumnya peta tile map ini memiliki zoom dari 1 yaitu mencakup keseluruhan bumi dan zoom 17 untuk melihat rumah-rumah. Jumlah gambar pada setiap level adalah perkalian antara x (bujur) dan y (lintang). Berikut tabel jumlah gambar per level.

LevelXYJumlah
20-30-316
30-70-764
40-150-15256
50-310-311024
60-630-634096
70-1270-12716384
80-2550-25565536
90-5110-511262144

Unduh

Pengunduhan gambar dengan jumlah banyak tersebut penulis menggunakan curl. Berikut perintah yang digunakan untuk melakukan pengunduhan.

curl --output '#1_#2.png' 'http://a.tiles.telegeography.com/maps/submarine-cable-map-2014/6/[0-63]/[0-63].png'

Gabung Gambar

Penggabungan gambar menggunakan program ImageMagick.

#!/bin/bash
function show_help
{
echo "Usage: $0 (-x xcoord) (-y ycoord) (-l level)"
echo " [-r x width] [-s y width] -h for help"
}
if [ $# -le 1 ]; then
show_help
exit 1
fi
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
## Note !1e0=png !1e3=webp !1e4=bin
G_SAT='https://www.google.com/maps/vt/pb=!1m5!1m4!1i$level!2i[$x-$x1]!3i[$y-$y1]!4i128!2m2!1e1!3i803!3m9!2sid!3sid!5e1105!12m1!1e4!12m1!1e47!12m1!1e3!4e0!5m1!1e0'
G_SAT_1='https://www.google.com/maps/vt/pb=!1m5!1m4!1i$level!2i[$x-$x1]!3i[$y-$y1]!4i128!2m2!1e1!3i803!3m9!2sid!3sid!5e1105!12m1!1e4!12m1!1e47!4e0!1e0'
G_MAP='https://www.google.com/maps/vt/pb=!1m5!1m4!1i$level!2i[$x-$x1]!3i[$y-$y1]!4i128!2m2!1e0!3i429133041!3m7!2sid!3sid!5e1105!12m1!1e47!12m1!1e3!4e0!5m1!1e0'
G_CON_0='https://www.google.com/maps/vt/pb=!1m4!1m3!1i$level!2i[$x-$x1]!3i[$y-$y1]!2m2!1e5!2sshading!2m2!1e6!2scontours!2m3!1e0!2sm!3i429133076!3m7!5e1105!12m1!1e67!12m1!1e63!12m1!1e3!4e0!5m2!5f1!6b1'
G_CON_1='https://www.google.com/maps/vt/pb=!1m4!1m3!1i$level!2i[$x-$x1]!3i[$y-$y1]!2m2!1e5!2sshading!2m2!1e6!2scontours!2m3!1e0!2sm!3i429133076!3m7!5e1105!12m1!1e67!12m1!1e63!5f1!6b1'
SOURCE_URL=$G_SAT
X_WIDTH=10
Y_WIDTH=10
EXT="png"
ANNOTATE=false
while getopts ":x:y:r:s:l:h?" opt; do
case $opt in
x ) x=$OPTARG ;;
y ) y=$OPTARG ;;
l ) level=$OPTARG ;;
r ) X_WIDTH=$OPTARG ;;
s ) Y_WIDTH=$OPTARG ;;
h ) show_help; exit 0 ;;
\? ) echo "Invalid option: -$OPTARG" >&2; exit 1 ;;
: ) echo "Option -$OPTARG requires an argument." >&2; exit 1 ;;
esac
done
shift $((OPTIND-1))
if [ -z "$x" -o -z "$y" -o -z "$level" ]; then
echo "Option -x -y -l required"
exit 1
fi
echo "x: $x, y: $y, level: $level, xrange: $X_WIDTH, yrange: $Y_WIDTH"
function calculate
{
let x1=x+$X_WIDTH
let y1=y+$Y_WIDTH
eval URL="$SOURCE_URL"
echo $URL
}
function fetch
{
echo "==> Downloading"
curl -C - --output "#1_#2.${EXT}" "$URL"
}
function merge
{
mkdir 'out'
if $ANNOTATE; then
echo "==> Annotating"
mogrify -gravity South \
-annotate +0+5 '%f' \
-pointsize 11 \
-fill white \
-bordercolor '#DFDFDF' \ #grey
-border 1 *.${EXT}
fi
echo "==> Merging"
for ((c=$x; c<=$x1; c++));
do
echo $c
if [ $x -lt 10 ]; then
for ((i=0; i<=9; i++));
do
echo -n "rename ${c}_${i} ";
a=${c}_${i}.${EXT};
j=`echo $a | cut -d _ -f 2` ;
mv $a `printf ${c}_0${j}`;
done
fi
montage -verbose \
-mode concatenate \
-tile 1x ${c}\_*.${EXT} out/${c}.${EXT}
done
cd 'out'
for ((a=0; a<=9; a++)); # $(seq 0 1 9)
do
if [ -z ${a}.${EXT} ]; then
mv ${a}.{EXT} 0${a}.${EXT};
fi
done;
let START_POS=x/10
let END_POS=x1/10
let DIFF=$END_POS-$START_POS
for ((a=START_POS; a<=END_POS; a++));
do
montage -verbose \
-mode concatenate \
-tile x1 ${a}*.${EXT} F${a}.${EXT}
done;
if [ $DIFF -gt 3 ]; then
let HALF=$START_POS+$DIFF/2
let NEXT=$HALF+1
montage -verbose \
-mode concatenate \
-tile x1 $(eval echo F{${START_POS}..${HALF}}.${EXT}) L.${EXT}
montage -verbose \
-mode concatenate \
-tile x1 $(eval echo F{${NEXT}..${END_POS}}.${EXT}) R.${EXT}
montage -verbose \
-mode concatenate \
-tile x1 L.${EXT} R.${EXT} FINAL.${EXT}
else
montage -verbose \
-mode concatenate \
-tile x1 $(eval echo F{${START_POS}..${END_POS}}.${EXT}) FINAL.${EXT}
fi
cd ".."
echo "==> Done merging"
}
function cleanup
{
echo "==> Cleanup"
mkdir "source"
mv *.${EXT} source/
mv out/FINAL.${EXT} .
convert -resize 1366x\> FINAL.${EXT} RE1000.${EXT}
}
function main
{
mkdir "${level}-${x}-${y}"
cd "${level}-${x}-${y}"
calculate
fetch
merge
cleanup
}
main
view raw gmaps-dl.sh hosted with ❤ by GitHub

Hasil

Migrating to Pelican Lini Waktu Space Race