Reputation: 346
I've made a lot of searches and found some useful resources but still having problems about calculation.
I want to calculate NE and SW coordinates for a specific tile.
This is my way :
Zoom = 11
x = 1188
y = 767
number of tile = 2 ^ 11 (equals 2048)
angle1 = 360 / 2048
longitude = (1188 * angle1) - 180
it works correct.
But latitude part is not :
angle2 = 170.1022575596 / (2048/2)
latitude = ((2048 / 2) - 767) * angle2
thanks in advance
Upvotes: 3
Views: 1580
Reputation: 370
Here I want to share a python version answer.
PS: [the last answer includes matlab and java implementations]
from math import atan, exp
z = 18.
x = 223576.
y = 101583.
pi = 3.1415926
alon1 = (x /pow(2.,z))*360.0 - 180.0
alon2 = ((x+1) /pow(2.,z))*360.0 - 180.0
an = pi-2.*pi*y/pow(2.,z)
alat1 = 180.0/pi*atan(0.5*(exp(an)-exp(-an)))
an = pi-2.*pi*(y+1)/pow(2.,z)
alat2 = 180.0/pi*atan(0.5*(exp(an)-exp(-an)))
print(alon1,alat1,alon2,alat2)
Upvotes: 0
Reputation: 21
The solution you are looking for is this:
z = 11
x = 1188
y = 767
pi = 3.14159
alon1 = (x /2^z)*360.0 - 180.0
alon2 = ((x+1) /2^z)*360.0 - 180.0
an = pi-2*pi*y/2^z
alat1 = 180.0/pi*atan(0.5*(exp(an)-exp(-an)))
an = pi-2*pi*(y+1)/2^z
alat2 = 180.0/pi*atan(0.5*(exp(an)-exp(-an)))
And you get the NW (alon1,alat1) & SE (alon2,alat2) coordinates for this specific tile.
Upvotes: 2