forked from sravankumar12/OSMmaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tile_calculator.sh
executable file
·61 lines (55 loc) · 1.37 KB
/
tile_calculator.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
xtile2long()
{
xtile=$1
zoom=$2
echo "${xtile} ${zoom}" | awk '{printf("%.9f", $1 / 2.0^$2 * 360.0 - 180)}'
}
long2xtile()
{
long=$1
zoom=$2
echo "${long} ${zoom}" | awk '{ xtile = ($1 + 180.0) / 360 * 2.0^$2;
xtile+=xtile<0?-0.5:0.5;
printf("%d", xtile ) }'
}
ytile2lat()
{
ytile=$1;
zoom=$2;
tms=$3;
if [ ! -z "${tms}" ]
then
# from tms_numbering into osm_numbering
ytile=`echo "${ytile}" ${zoom} | awk '{printf("%d\n",((2.0^$2)-1)-$1)}'`;
fi
lat=`echo "${ytile} ${zoom}" | awk -v PI=3.14159265358979323846 '{
num_tiles = PI - 2.0 * PI * $1 / 2.0^$2;
printf("%.9f", 180.0 / PI * atan2(0.5 * (exp(num_tiles) - exp(-num_tiles)),1)); }'`;
echo "${lat}";
}
lat2ytile()
{
lat=$1;
zoom=$2;
tms=$3;
ytile=`echo "${lat} ${zoom}" | awk -v PI=3.14159265358979323846 '{
tan_x=sin($1 * PI / 180.0)/cos($1 * PI / 180.0);
ytile = (1 - log(tan_x + 1/cos($1 * PI/ 180))/PI)/2 * 2.0^$2;
ytile+=ytile<0?-0.5:0.5;
printf("%d", ytile ) }'`;
if [ ! -z "${tms}" ]
then
# from oms_numbering into tms_numbering
ytile=`echo "${ytile}" ${zoom} | awk '{printf("%d\n",((2.0^$2)-1)-$1)}'`;
fi
echo "${ytile}";
}
10/731/429
ZOOM=10;
TILE_X=731;
TILE_Y=429;
n=$(ytile2lat `expr ${TILE_Y}` ${ZOOM})
s=$(ytile2lat `expr ${TILE_Y} + 1` ${ZOOM})
e=$(xtile2long `expr ${TILE_X} + 1` ${ZOOM})
w=$(xtile2long `expr ${TILE_X}` ${ZOOM})
echo "bbox=$w,$s,$e,$n"