1.坐标转行列号(经纬度)
def deg2num4490(lon, lat, zoom):
"""
Lon./lat. to tile numbers
:param lat: latitude degree
:param lon: longitude degree
:param zoom: zoom level
:return:
"""
n = 2.0 ** zoom
x = int((lon + 180.0) / 360.0 * n)
y = int((90 - lat) / 360.0 * n )
return x, y
2.行列号转坐标(经纬度)
def num2deg4490(x, y, zoom):
"""
tile number to lon./lat
:param x: x tile num
:param y: y tile num
:param zoom: zoom level
:return:the NW-corner of the square. use the function with xtile+1 and ytile+1 to get the other corners.
"""
n = 2.0 ** zoom
lon_min = (x / n) * 360.0 - 180.0
lat_min = 90.0 - (((y + 1) / n) * 360.0)
lon_max = ((x + 1) / n) * 360.0 - 180.0
lat_max = 90.0 - ((y / n) * 360.0)
return lon_min, lat_min, lon_max, lat_max
3.坐标转行列号(墨卡托)
def deg2num3857(lon, lat, zoom):
"""
Lon./lat. to tile numbers
:param lat: latitude degree
:param lon: longitude degree
:param zoom: zoom level
:return:
"""
lat_rad = math.radians(lat)
n = 2.0 ** zoom
x = int((lon + 180.0) / 360.0 * n)
y = int((1.0 - math.asinh(math.tan(lat_rad)) / math.pi) / 2.0 * n)
return x, y
4.行列号转坐标(墨卡托)
def num2deg3857(x, y, zoom):
"""
tile number to lon./lat
:param x: x tile num
:param y: y tile num
:param zoom: zoom level
:return:the NW-corner of the square. use the function with xtile+1 and ytile+1 to get the other corners.
"""
n = 2.0 ** zoom
lon_min = x / n * 360.0 - 180.0
rad_min = math.atan(math.sinh(math.pi * (1 - 2 * (y + 1) / n)))
lat_min = math.degrees(rad_min)
lon_max = ((x + 1) / n) * 360.0 - 180.0
rad_max = math.atan(math.sinh(math.pi * (1 - 2 * y / n)))
lat_max = math.degrees(rad_max)
return lon_min, lat_min, lon_max, lat_max