Carnet Wiki

Script gettiles.sh

Version 3 — Août 2023 JLuc

Contexte : https://discuter.spip.net/t/gis-et-les-fonds-de-carte-stamen/171775

#!/bin/bash
# By JLuc


bash
# !/bin/bash
if [ « $1 » = «  » ] || [ « $1 » = « -h » ] || [ « $1 » = « - ? » ]
then
echo « Usage : gettiles.sh [-c nomcollection (toner-labels watercolor )] [-z zoomlevel (5)] [-startx x_debut_scanport ()] [-lastx x_fin_scanport] [-starty y_debut_scanport ()] [-lasty y_fin_scanport] [-w waitseconds (2)] [—explain] »
echo « Les options doivent etre IMPÉRATIVEMENT dans cet ordre ! »
echo « Une des options peut être omise mais elles doivent être dans cet ordre »
echo « Il faut au moins une option (le zoomlevel par exemple) »
echo « -h : aide »
echo « -c avant un nom de collection stamen (toner-labels, watercolor...
 »
echo «  Une des options peut être omise mais elles doivent être dans cet ordre  »
echo «  Il faut au moins une option ( le zoomlevel par exemple ) »
echo « - h  : aide  »
echo « - c avant un nom de collection stamen ( watercolor ou tonerlabel ) »
echo « -z : zoom level (0 à 12, mais au delà de 4 il faut cibler et pas choper les tiles du monde entier) »
echo « -startx, -lastx, -starty, -lasty : début et fin du scanport »
echo « -w : temps d’attente après chaque récupération. , pour éviter saturation et blacklist  »
echo « — explain  : ne fait qu’expliquer le paramétrage choisi mais ne lance rien  »
exit
fi Éviter saturation et blacklisture. En secondes. Peut être décimal, « 
echo »—explain : ne fait qu’expliquer le paramétrage choisi mais ne lance rien"
echo «  »
echo « Scanports couvrant la France : »
echo « - zoom 8 : 126-133 x 85-94 »
echo « - zoom 9 : 249-267 x 171-189 »
echo « - zoom 10 : 498-535 x 645-681 »
echo « - zoom 11 : 996-1070 x 685-757 »
echo « - zoom 12 : 1994-2141 x1369-1515 »
exit
fi

collec=toner-labels collec=watercolor # default
if [ « $1 » = « -c » ] && [ « $2 » != «  » ]
then
collec=$2
shift
shift
fi

zoomlevel=5 # default
if [ « $1 » = « -z » ] && [ « $2 » != «  » ]
then
zoomlevel=$2
shift
shift
fi

let side=2**zoomlevel
# let side=echo 2^\($zoomlevel*2\) | bc

startx=0
if [ « $1 » = « -startx » ] && [ « $2 » != «  » ]
then
startx=$2
shift
shift
fi

let lastx=side-1
if [ « $1 » = « -lastx » ] && [ « $2 » != «  » ]
then
lastx=$2
shift
shift
fi

starty=0
if [ « $1 » = « -starty » ] && [ « $2 » != «  » ]
then
starty=$2
shift
shift
fi

let lasty=side-1
if [ « $1 » = « -lasty » ] && [ « $2 » != «  » ]
then
lasty=$2
shift
shift
fi

waitseconds=2 # default prevents blacklisting
- sinon accès refusé
if [ « $1 » = « -w » ] && [ « $2 » != «  » ]
then
waitseconds=$2
shift
shift
fi

if [ « $1 » != «  » ] && [ « $1 » != « —explain » ]
then
echo « Erreur de parametre : $1 »
exit
fi

echo collec = $collec
echo zoomlevel = $zoomlevel
echo side = $side
echo « x de $startx à $lastx »
echo « y de $starty à $lasty »
echo wait $waitseconds seconds
echo ====
let wx=$lastx-$startx+1
let wy=$lasty-$starty+1
let ntiles=wx*wy

echo Pour le parcours de $zoomlevel/$startx-$lastx/$starty-$lasty, il y a $ntiles tuiles à récupérer
let nbsec=$ntiles$waitseconds
let nbmin=$nbsec/60
let nbheure=$nbsec/3600
echo ce qui se fera en $nbsec s, soit $nbmin mn ou un peu plus de $nbheure heures
echo ====
if [ « $1 » = « —explain » ]
then
exit
fi

[ ! -d $collec ] && mkdir $collec
[ ! -d $collec/$zoomlevel ] && mkdir $collec/$zoomlevel

echo maxside=$maxside

for x in $(seq $startx $lastx)
do
echo
echo « #################################### »
echo « ### create $collec/$zoomlevel/$x »
echo
[ ! -d $collec/$zoomlevel/$x ] && mkdir $collec/$zoomlevel/$x
for y in $(seq $starty $lasty)
do
echo « ($x x $y) »
wget http://stamen-tiles-d.a.ssl.fastly.net/$collec/$zoomlevel/$x/$y.jpg -O $collec/$zoomlevel/$x/$y.jpg
sleep $waitseconds
done
done
```