OSM:从球形墨卡托"EPSG:900913"中的投影坐标转换关系.到"EPSG:4326";座标 [英] OSM: convert ties from projected coordinates in spherical mercator "EPSG:900913" to "EPSG:4326" coordinates
问题描述
我正在使用带有图层的地图(来自示例):
I'm using a map with a layer (from the example):
var lonLat = new OpenLayers.LonLat(40.4088576, -86.8576718)
.transform(
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
map.getProjectionObject() // to Spherical Mercator Projection
);
在moveend上,我得到中心坐标:
on moveend i'm get center coordinates:
map.getCenter();
map.getZoom();
和缩放级别:4925535.4503328,-9668990.0134335、12
and zoom level: 4925535.4503328, -9668990.0134335, 12
使用文档中的算法
public PointF TileToWorldPos(double tile_x, double tile_y, int zoom)
{
PointF p = new Point();
double n = Math.PI - ((2.0 * Math.PI * tile_y) / Math.Pow(2.0, zoom));
p.X = (float)((tile_x / Math.Pow(2.0, zoom) * 360.0) - 180.0);
p.Y = (float)(180.0 / Math.PI * Math.Atan(Math.Sinh(n)));
return p;
}
我得到Y〜90和X〜432662
i get Y ~ 90, and X ~ 432662
但是我需要坐标范围:-180..180
but i need coordinates in bounds: -180..180
类似的东西:40.4088576,-86.8576718
something like: 40.4088576, -86.8576718
怎么了?
推荐答案
为什么不让OpenLayers为您重新投影呢?因此,如果您希望将中心点设为WGS84,则只需执行以下操作:
Why not just get OpenLayers to project it back for you? So if you want the centre point as WGS84 then just do:
var center = map.getCenter().transform(map.getProjectionObject(),
new OpenLayers.Projection("EPSG:4326"));
我想您会发现无论如何,它都会做您想要的事情,至少在我理解正确的问题之后……
I think you'll find that will do what you want anyway, at least if I've understood the question right...
顺便说一句,EPSG:4326是您似乎正在寻找的自然WGS84纬度/经度值-大数字是球形墨卡托投影的坐标,即EPSG:900913.
By the way, EPSG:4326 is the natural WGS84 lat/lon values that you seem to be looking for - the large numbers are the projected coordinates in spherical mercator, which is EPSG:900913.
这篇关于OSM:从球形墨卡托"EPSG:900913"中的投影坐标转换关系.到"EPSG:4326";座标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!