我有一個邊框:轉換緯度/長到X,內Y位置邊框
Left -122.27671
Bottom 37.80445
Right -122.26673
Top 37.81449
它也可以轉化爲NE緯度/經度和SW緯度/龍
在該邊界框,我想找到特定緯度/經度的X,Y位置。這將使用墨卡託投影。
我見過的答案是找到X,Y採用墨卡託投影的世界地圖上的位置,而不是特定的經/緯度範圍內。
任何幫助表示讚賞!
UPDATE 把這個從我看到的另一個問題放在一起。任何人都可以驗證,如果這看起來合法?
map_width = 1240
map_height = 1279
map_lon_left = -122.296916
map_lon_right = -122.243380
map_lon_delta = map_lon_right - map_lon_left
map_lat_bottom = 37.782368
map_lat_bottom_degree = map_lat_bottom * Math::PI/180
def convert_geo_to_pixel(lat, long)
x = (long - map_lon_left) * (map_width/map_lon_delta)
lat = lat * Math::PI/180
world_map_width = ((map_width/map_lon_delta) * 360)/(2 * Math::PI)
map_offset_y = (world_map_width/2 * Math.log((1 + Math.sin(map_lat_bottom_degree))/(1 - Math.sin(map_lat_bottom_degree))))
y = map_height - ((world_map_width/2 * Math.log((1 + Math.sin(lat))/(1 - Math.sin(lat)))) - map_offset_y)
return [x, y]
end
是我在上面使用的代碼不正確嗎?有您的例子輸出'X,y'當一個邊框內給予緯度/經度很難理解? – theartofbeing
您的x計算是正確的。你似乎錯了。我的緯度相當於你的緯度,B = map_lat_bottom,T = map_lat_top(沒有看到它在你的代碼) – MBo
我從http://stackoverflow.com/questions/2103924/mercator-longitude-and-latitude-抄我的解決辦法計算到的X和Y型上一個裁剪地圖的最/ 10401734#10401734 我相信map_lat左和右是左上角和右上角。既然我們知道角落的位置,我們需要的只是底部的緯度來完成正方形。這就是我解釋這個解決方案的方式? – theartofbeing