从纬度、经度转换为 x、y [英] Convert from latitude, longitude to x, y

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

问题描述

我想将 GPS 位置(纬度、经度)转换为 x,y 坐标.我找到了很多关于这个主题的链接并应用了它,但它并没有给我正确的答案!

I want to convert GPS location (latitude, longitude) into x,y coordinates. I found many links about this topic and applied it, but it doesn't give me the correct answer!

我正在按照以下步骤测试答案:(1) 首先,我取两个位置并使用地图计算它们之间的距离.(2) 然后将这两个位置转换为 x,y 坐标.(3) 然后再次计算 x,y 坐标中两点之间的距离看看它是否在第 (1) 点给我相同的结果.

I am following these steps to test the answer: (1) firstly, i take two positions and calculate the distance between them using maps. (2) then convert the two positions into x,y coordinates. (3) then again calculate distance between the two points in the x,y coordinates and see if it give me the same result in point(1) or not.

我找到了以下解决方案之一,但它没有给我正确的答案!

one of the solution i found the following, but it doesn't give me correct answer!

latitude = Math.PI * latitude / 180;
longitude = Math.PI * longitude / 180;

// adjust position by radians
latitude -= 1.570795765134; // subtract 90 degrees (in radians)

// and switch z and y 
xPos = (app.radius) * Math.sin(latitude) * Math.cos(longitude);
zPos = (app.radius) * Math.sin(latitude) * Math.sin(longitude);
yPos = (app.radius) * Math.cos(latitude);

我也试过这个链接,但仍然不能很好地与我合作!

also i tried this link but still not work with me well!

任何帮助如何从(纬度,经度)转换为(x,y)?

any help how to convert from(latitude, longitude) to (x,y) ?

谢谢,

推荐答案

不存在确切的解决方案

没有从球体到平面的等轴测图.当您将球体中的纬度/经度坐标转换为平面中的 x/y 坐标时,您不能希望此操作会保留所有长度.你必须接受某种变形.确实存在许多不同的地图投影,它们可以在长度、角度和面积的保留之间实现不同的折衷.对于地球表面的小部分,横向墨卡托相当常见.您可能听说过 UTM.但是还有更多.

No exact solution exists

There is no isometric map from the sphere to the plane. When you convert lat/lon coordinates from the sphere to x/y coordinates in the plane, you cannot hope that all lengths will be preserved by this operation. You have to accept some kind of deformation. Many different map projections do exist, which can achieve different compromises between preservations of lengths, angles and areas. For smallish parts of earth's surface, transverse Mercator is quite common. You might have heard about UTM. But there are many more.

您引用的公式计算 x/y/z,即 3D 空间中的一个点.但即使在那里,您也不会自动获得正确的距离.球体表面上两点之间的最短距离将穿过该球体,而地球上的距离主要是沿表面的测地线长度.所以它们会更长.

The formulas you quote compute x/y/z, i.e. a point in 3D space. But even there you'd not get correct distances automatically. The shortest distance between two points on the surface of the sphere would go through that sphere, whereas distances on the earth are mostly geodesic lengths following the surface. So they will be longer.

如果您要绘制的地球表面部分比较小,那么您可以使用一个非常简单的近似值.你可以简单地用横轴x来表示经度λ,纵轴y来表示纬度φ.但是,它们之间的比例不应该是 1:1.相反,您应该使用 cos(φ0) 作为纵横比,其中 φ0 表示靠近地图中心的纬度.此外,要将角度(以弧度测量)转换为长度,您需要乘以地球的半径(在此模型中假定为球体).

If the part of the surface of the earth which you want to draw is relatively small, then you can use a very simple approximation. You can simply use the horizontal axis x to denote longitude λ, the vertical axis y to denote latitude φ. The ratio between these should not be 1:1, though. Instead you should use cos(φ0) as the aspect ratio, where φ0 denotes a latitude close to the center of your map. Furthermore, to convert from angles (measured in radians) to lengths, you multiply by the radius of the earth (which in this model is assumed to be a sphere).

  • x = r λ cos(φ0)
  • y = r φ
  • x = r λ cos(φ0)
  • y = r φ

这是简单的等角投影.在大多数情况下,您只能计算一次 cos(φ0),这使得后续大量点的计算非常便宜.

This is simple equirectangular projection. In most cases, you'll be able to compute cos(φ0) only once, which makes subsequent computations of large numbers of points really cheap.

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

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