我认为这并不是一个很难解决的问题,但我对准确性是否绝对正确表示怀疑。首先,您必须使用gdal2tiles代码将中心纬度/经度转换为像素。如果我愿意的话,可以将其转换为稳定的代码以查找角坐标。
这是一个Python代码:
tileSize = 256
initialResolution = 2 * math.pi * 6378137 / tileSize
# 156543.03392804062 for tileSize 256 pixels
originShift = 2 * math.pi * 6378137 / 2.0
# 20037508.342789244
def LatLonToMeters( lat, lon ):
"Converts given lat/lon in WGS84 Datum to XY in Spherical Mercator EPSG:900913"
mx = lon * originShift / 180.0
my = math.log( math.tan((90 + lat) * math.pi / 360.0 )) / (math.pi / 180.0)
my = my * originShift / 180.0
return mx, my
def MetersToPixels( mx, my, zoom):
"Converts EPSG:900913 to pyramid pixel coordinates in given zoom level"
res = Resolution( zoom )
px = (mx + originShift) / res
py = (my + originShift) / res
return px, py
# Dont forget you have to convert your projection to EPSG:900913
mx = -8237494.4864285 #-73.998672
my = 4970354.7325767 # 40.714728
zoom = 12
pixel_x, pixel_y = LatLonToMeters(MetersToPixels( mx, my, zoom))
然后,您可以通过查看下图使用加法或减法:
如果要找到A点:
x = pixel_x - 200
y = pixel_y + 200
或者您想找到B点:
x = pixel_x + 200
y = pixel_y + 200
最后要做的就是将像素转换为经/纬度。
def PixelsToMeters( px, py, zoom):
"Converts pixel coordinates in given zoom level of pyramid to EPSG:900913"
res = Resolution(zoom)
mx = px * res - originShift
my = py * res - originShift
return mx, my
def MetersToLatLon( mx, my ):
"Converts XY point from Spherical Mercator EPSG:900913 to lat/lon in WGS84 Datum"
lon = (mx / originShift) * 180.0
lat = (my / originShift) * 180.0
lat = 180 / math.pi * (2 * math.atan(math.exp(lat * math.pi / 180.0)) - math.pi / 2.0)
return lat, lon
#Result
llx, lly = MetersToLatLon( PixelsToMeters( x, y, zoom) )
所以我得到的结果是:
point A - UpperLeftLatLon = 40.7667530977 -74.0673365509
point B - UpperRightLatLon = 40.7667530977 -73.9300074493
point C - LowerRightLatLon = 40.6626622172 -73.9300074493
point D - LowerLeftLatLon = 40.6626622172 -74.0673365509
希望对您有帮助。