使用python将纬度和经度转换为x和y网格系统

问题描述 投票:4回答:3

我有纬度和经度值的文件,我想以km为单位转换x和y我想测量每个点的距离。

例如我制作纬度和经度的第一个点(分别是51.58,-124.6)

到(0,0)我的x和y系统所以基本上我想找出其他点是什么和他们从原点的位置所以我想找到什么51.56(纬度)-123.64(长)在(x) ,y)以km为单位,依此类推文件的其余部分。

我想在python中完成所有这些,是否有一些排序代码?

例如,我在网上找到了网站

http://www.whoi.edu/marine/ndsf/cgi-bin/NDSFutility.cgi?form=0&from=LatLon&to=XY

我想要做什么,我只是不知道他们是怎么做的。

python latitude-longitude coordinate-systems
3个回答
7
投票

以下内容非常接近(以km为单位)。如果你需要比这更好,你必须更加努力地学习数学 - 例如通过遵循给定的一些链接。

import math
dx = (lon1-lon2)*40000*math.cos((lat1+lat2)*math.pi/360)/360
dy = (lat1-lat2)*40000/360

变量名称应该非常明显。这给了你

dx = 66.299 km (your link gives 66.577)
dy = 2.222 km (link gives 2.225)

一旦选择坐标(例如,lon1, lat1)作为原点,就应该很容易看到如何计算所有其他XY坐标。

注 - 因子40,000是以千米为单位的地球周长(跨极点测量)。这会让你接近。如果你看一下你提供的链接的来源(你需要挖掘一下才能找到javascript which is in a separate file),你会发现它们使用了一个更复杂的等式:

function METERS_DEGLON(x)
{  
   with (Math)
   {
      var d2r=DEG_TO_RADIANS(x);
      return((111415.13 * cos(d2r))- (94.55 * cos(3.0*d2r)) + (0.12 * cos(5.0*d2r)));
   }
}

function METERS_DEGLAT(x)
{
   with (Math)
   {
      var d2r=DEG_TO_RADIANS(x);
      return(111132.09 - (566.05 * cos(2.0*d2r))+ (1.20 * cos(4.0*d2r)) - (0.002 * cos(6.0*d2r)));
   }
}

在我看来,他们实际上正在考虑到地球不是一个球体的事实......但即便如此,当你做出假设时,你可以把地球当作一架飞机对待你将会有一些错误。我肯定他们的公式错误较小......


1
投票

UTM预测以米为单位。所以你可以在这个链接上使用像utm lib这样的东西:

https://pypi.python.org/pypi/utm

谷歌搜索python lat lon到UTM将指向几个选项。

UTM区域的经度为6度,从本初子午线的0开始。每个UTM区域的原点位于赤道(x轴),y轴位于最西经度。这使得网格向北和向东都是正的。您可以计算距离这些结果的距离。值在UTM区域的中间最准确。

您还应该知道原始lat lon值所基于的数据,并在转换中使用相同的数据。


1
投票

您可以使用Great Circle Distance formula获取GPS点之间的距离。纬度和经度位于地理坐标系中,因此您不能只转换为平面2D网格并使用欧氏距离。您可以通过采用像(X,Y)这样的任意点,将其设置为原点(就像您已经完成的那样)将足够接近的点转换为近似网格,然后使用大圆距离和bearing绘制相对于在飞机上彼此相对,但这是一个近似值。


0
投票

如果你要使用3D系统,这些功能将:

def arc_to_deg(arc):
    """convert spherical arc length [m] to great circle distance [deg]"""
    return float(arc)/6371/1000 * 180/math.pi

def deg_to_arc(deg):
    """convert great circle distance [deg] to spherical arc length [m]"""
    return float(deg)*6371*1000 * math.pi/180

def latlon_to_xyz(lat,lon):
    """Convert angluar to cartesian coordiantes

    latitude is the 90deg - zenith angle in range [-90;90]
    lonitude is the azimuthal angle in range [-180;180] 
    """
    r = 6371 # https://en.wikipedia.org/wiki/Earth_radius
    theta = math.pi/2 - math.radians(lat) 
    phi = math.radians(lon)
    x = r * math.sin(theta) * math.cos(phi) # bronstein (3.381a)
    y = r * math.sin(theta) * math.sin(phi)
    z = r * math.cos(theta)
    return [x,y,z]

def xyz_to_latlon (x,y,z):
    """Convert cartesian to angular lat/lon coordiantes"""
    r = math.sqrt(x**2 + y**2 + z**2)
    theta = math.asin(z/r) # https://stackoverflow.com/a/1185413/4933053
    phi = math.atan2(y,x)
    lat = math.degrees(theta)
    lon = math.degrees(phi)
    return [lat,lon]
© www.soinside.com 2019 - 2024. All rights reserved.