OSM: convert ties from projected coordinates in spherical mercator “EPSG:900913” to “EPSG:4326” coordinates

萝らか妹 提交于 2019-12-06 06:56:12

问题


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
                );

on moveend i'm get center coordinates:

map.getCenter();
map.getZoom();

and zoom level: 4925535.4503328, -9668990.0134335, 12

Using algorithm from documentation

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;
}

i get Y ~ 90, and X ~ 432662

but i need coordinates in bounds: -180..180

something like: 40.4088576, -86.8576718

what is wrong?


回答1:


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...

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.



来源:https://stackoverflow.com/questions/7569179/osm-convert-ties-from-projected-coordinates-in-spherical-mercator-epsg900913

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!