在给定图片上将 long/lat 转换为像素 x/y [英] Convert long/lat to pixel x/y on a given picture

查看:23
本文介绍了在给定图片上将 long/lat 转换为像素 x/y的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张莫斯科的城市地图.我们用一些艺术元素修改了一张谷歌地图图像,但 GPS 坐标和像素之间的关系保持不变.

I have a city map of Moscow. We modified a Google Maps image with some artistic elements, but the relation between GPS coordinates and pixels remains the same.

问题:如何将 GPS 坐标从我们拥有的各种数据点转换为图像中的像素坐标?

Problem: How do I convert GPS coordinates from various data points we have into pixel coordinates in the image?

理想情况下,我可以在 Javascript 中执行此操作,但 PHP 可以.

Ideally I can do this in Javascript, but PHP would be OK.

我知道在小尺度上(例如在城市尺度上)它可以制作得足够简单(有必要了解哪个地理坐标具有图片角之一,然后了解地理坐标中一个像素的价格"在一个图片分别在 OX 和 OY 轴上).

I know that on small scales (for example on city scales) it to make simply enough (it is necessary to learn what geographic coordinates has one of picture corners, then to learn "price" of one pixel in geographic coordinates on a picture on axes OX and OY separately).

但在大尺度(国家尺度)上,一个像素的价格"将不是一个常数,而且变化很大,上述方法无法应用.

But on the big scales (country scale) "price" of one pixel will be not a constant, and will vary strongly enough and the method described above cannot be applied.

如何在国家范围内解决问题?

How to solve a problem on country scales?

更新:

我不使用API​​ Google Maps,我只有:对象的地理坐标(它们来自谷歌地图),我的网站上还有一张简单的图片*.gif,我必须在其中绘制一个点对应的地理坐标.

I do not use API Google Maps, I have only: geographic coordinates of the object (they are from google maps), I still have at my site a simple picture *. gif, in which I must draw a point corresponding geographic coordinates.

推荐答案

这一切的关键是理解 地图投影.正如其他人指出的那样,失真的原因是球形(或更准确地说是椭圆体)地球被投影到一个平面上.

The key to all of this is understanding map projections. As others have pointed out, the cause of the distortion is the fact that the spherical (or more accurately ellipsoidal) earth is projected onto a plane.

为了实现您的目标,您首先必须了解有关数据的两件事:

In order to achieve your goal, you first must know two things about your data:

  1. 您的地图所在的投影.如果它们纯粹来自 Google 地图,那么他们很可能正在使用球形墨卡托投影.
  2. 您的纬度/经度坐标使用的地理坐标系.这可能会有所不同,因为在地球上定位经纬度有不同的方法.最常见的 GCS,用于大多数网络地图应用程序和 GPS,是 WGS84.莉>
  1. The projection your maps are in. If they are purely derived from Google Maps, then chances are they are using a spherical Mercator projection.
  2. The geographic coordinate system your latitude/longitude coordinates are using. This can vary, because there are different ways of locating lat/longs on the globe. The most common GCS, used in most web-mapping applications and for GPS's, is WGS84.

我假设您的数据位于这些坐标系中.

I'm assuming your data is in these coordinate systems.

球形墨卡托投影为地球表面定义了一个以米为单位的坐标对.这意味着,对于每个纬度/经度坐标,都有一个匹配的米/米坐标.这使您可以使用以下过程进行转换:

The spherical Mercator projection defines a coordinate pair in meters, for the surface of the earth. This means, for every lat/long coordinate there is a matching meter/meter coordinate. This enables you to do the conversion using the following procedure:

  1. 找到图像角的 WGS84 纬度/经度.
  2. 将 WGS 纬度/经度转换为球形墨卡托投影.那里有转换工具,我最喜欢使用 cs2cs 工具,它是 PROJ4 项目 的一部分.
  3. 您可以安全地进行简单的线性变换,以在图像上的点与球形墨卡托投影中地球上的点之间进行转换,然后再返回.

为了从一个WGS84点到图像上的一个像素,现在的程序是:

In order to go from a WGS84 point to a pixel on the image, the procedure is now:

  1. 将经纬度投影到球形墨卡托.这可以使用 proj4js 库来完成.
  2. 使用上面发现的线性关系将球面墨卡托坐标转换为图像像素坐标.

您可以像这样使用 proj4js 库:

You can use the proj4js library like this:

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

这篇关于在给定图片上将 long/lat 转换为像素 x/y的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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