使用python将经度和纬度转换为x和y网格系统 [英] convert latitude and longitude to x and y grid system using python

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

问题描述

我有一个包含纬度和经度值的文件,我想将x和y转换为km 我想测量每个点的距离.

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

到我的x和y系统中的(0,0),所以基本上我想找出其他点是什么,以及它们从原点的位置,所以我想找出51.56(lat)-123.64(long)是什么在[x,y]中以km为单位,依此类推.

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

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

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

确实是我想做的,我只是不知道他们是怎么做的.

解决方案

以下内容使您非常接近(答案以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是地球的周长,以km为单位(跨两极测量).这使您接近.如果您查看提供的链接的来源(您必须仔细研究以找到http://www.whoi.edu/marine/ndsf/cgi-bin/NDSFutility.cgi?form=0&from=LatLon&to=XY

does exactly want i want to do, I just don't know how they do it.

解决方案

The following gets you pretty close (answer in km). If you need to be better than this, you have to work harder at the math - for example by following some of the links given.

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

Variable names should be pretty obvious. This gives you

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

Once you pick coordinates (for example, lon1, lat1) as your origin, it should be easy to see how to compute all the other XY coordinates.

Note - the factor 40,000 is the circumference of the earth in km (measured across the poles). This gets you close. If you look at the source of the link you provided (you have to dig around a bit to find the javascript which is in a separate file) you find that they use a more complex equation:

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

It looks to me like they are actually taking account of the fact that the earth is not exactly a sphere... but even so when you are making the assumption you can treat a bit of the earth as a plane you are going to have some errors. I'm sure with their formulas the errors are smaller...

这篇关于使用python将经度和纬度转换为x和y网格系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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