将X,Y像素转换为经度和纬度 [英] Convert X,Y pixel to Longitude and Latitude

查看:55
本文介绍了将X,Y像素转换为经度和纬度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一幅8640x11520像素的图像,它来自地图的真实比例部分。我需要把我的x,y点转换成坐标,有没有人有办法找到它??

var mapWidth = 8640;
var mapHeight = 11520;

var mapLatitudeStart = 28.349768989955244;
var mapLongitudeStart = -81.55803680419922;

var maxLatitude = 28.349806758250104;
var maxLongitude = -81.541128;

var pointNeedConversion = {'x': 4813.10 'y': 2674.84};
var pointLatitude = ??

推荐答案

在映射到经度/经度时,请注意,不能使用线性比例执行此操作,而必须检查应用于地图的投影类型,然后相应地转换坐标。

通常地图是WGS84 Projections,因此您必须对墨卡托投影应用反演公式。

这项任务不是微不足道的,所以我的建议是依靠Proj4js

这样的库

库的使用很简单,您可以提供一个参考系进行操作,然后可以在另一个投影上转换坐标。

    // include the library
    <script src="lib/proj4js-combined.js"></script>  //adjust the path for your server
                                                     //or else use the compressed version
    // creating source and destination Proj4js objects
    // once initialized, these may be re-used as often as needed
    var source = new Proj4js.Proj('EPSG:4326');    //source coordinates will be in Longitude/Latitude, WGS84
    var dest = new Proj4js.Proj('EPSG:3785');     //destination coordinates in meters, global spherical mercators projection, see http://spatialreference.org/ref/epsg/3785/


    // transforming point coordinates
    var p = new Proj4js.Point(-76.0,45.0);   //any object will do as long as it has 'x' and 'y' properties
    Proj4js.transform(source, dest, p);      //do the transformation.  x and y are modified in place

    //p.x and p.y are now EPSG:3785 in meters

代码段积分:Convert long/lat to pixel x/y on a given picture

工作示例:

var dest = new proj4.Proj('EPSG:4326'); //destination coordinates coordinates will be in Longitude/Latitude, WGS84 , global spherical mercators projection, see http://spatialreference.org/ref/epsg/3785/     
var source = new proj4.Proj('EPSG:3785'); //source coordinates in meters

$("#convert").on("click", function(){
    var p = new proj4.Point($("#x").val(), $("#y").val() );
    proj4.transform(source, dest, p);
    alert("lng : " +p.x + " 
lat : " + p.y);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.3/proj4.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
x : <input type="number" id="x" />
y : <input type="number" id="y" />
<button id="convert">Convert</button>

注意:如果您打算使用地图角点绘制GPS信号,了解该角点的经度是非常重要的。

这里有一个图形示例,直观地解释了为什么线性比例不合适:

仔细观察格陵兰岛的大小,在墨卡托投影空间坐标上,它看起来比北美大。当然不是!

这篇关于将X,Y像素转换为经度和纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆