将纬度,经度转换为距赤道的距离(以公里为单位),然后四舍五入为最接近的公里 [英] Convert latitude, longitude to distance from equator in kilometers and round to nearest kilometer

查看:530
本文介绍了将纬度,经度转换为距赤道的距离(以公里为单位),然后四舍五入为最接近的公里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我拥有的每个坐标,我发现距赤道的距离(以千米为单位)为我提供了两个距离:

For each coordinate I have, I find the distance from the equator in kilometers giving me two distances:

from pyproj import Geod
wgs84_geod = Geod(ellps='WGS84')    
_,_, lon_dist = wgs84_geod.inv(0, 0,lon, 0)
_,_, lat_dist = wgs84_geod.inv(0, 0,0, lat)

为进行健全性检查,我可以按以下方式从这些值重新计算原始坐标(假设从赤道坐标(0,0)开始的方向是北和西:

As a sanity check,I can recalculate the original coordinate from these values as follows (assume the direction from the equator coordinate (0,0) is North and West:

_, new_lat, _ = wgs84_geod.fwd(0,0, 0, lat_dist)
new_lon, _, _ = wgs84_geod.fwd(0, 0, 90, lon_dist)

这使我恢复了开始时的坐标.

This gives me back the same coordinates I started with.

现在,我想找到最接近我的坐标的公里点.我将lon_dist和lat_dist四舍五入到距赤道数公里.

Now I want to find the closest kilometer point to my coordinate. I round the lon_dist and lat_dist to kilometers from the equator values.

lat_km_dist = round(lat_dist/1000)*1000 #to nearest km and back to meters
lon_km_dist = round(lon_dist/1000)*1000 

我以与以前相同的方式使用这些距离获取坐标

I get coordinates using these distances in the same way as before

_, km_lat, _ = wgs84_geod.fwd(0,0, 0, lat_km_dist)
km_lon, _, _ = wgs84_geod.fwd(0, 0, 90, lon_km_dist)

逻辑应该是,对于同一区域中的多个坐标,任何km_lat,km_lon对之间的最近距离应为1km. 在北/南轴上都是如此,但是对于经度,距离会根据我所在的纬度而变化. 我将附加两个屏幕快照,以可视化问题,其中km_lat,km_lon坐标由面积为1 km的多边形中心的黑色圆圈表示.

The logic should be that for multiple coordinates in the same area, the closest distance between any km_lat, km_lon pair should be 1km. This is true in the North/South axis, but for longitudes the distance varies depending on which latitude I'm at. I'm attaching two screenshots to visualize the problem where the km_lat, km_lon coordinates are represented by black circles at the center of polygons with an area of 1km.

我该如何纠正?

推荐答案

该算法的基本作用是在赤道(lat = 0)和主子午线上(lon = 0).然后,它可以有效地在椭球上构造这些点的笛卡尔积的网格.

What this algorithm is essentially doing is that it constructs an equidistant mesh (with points 1km apart) on the equator (lat=0) and the main meridian (lon=0). It then effectively constructs a grid on the ellipsoid as a Cartesian product of these points.

但是,纬度/经度坐标不会形成笛卡尔坐标系,由这些网格点生成的平行度/经度定义为正方形",其大小不仅取决于特定的经度,还取决于纬度.在理想球体上,这将在南北方向上起作用,因为这样,lon = 0上的等距(就大圆距离而言)网格在纬度上也是等距的(纬度差等于球体的半径).

However, the lat/lon coordinates do not form a Cartesian frame, the resulting parallels/meridians generated by these grid points define "squares" the size of which depends not only on the particular longitude, but latitude as well. On a perfect sphere, this would work in the north-south direction since then an equidistant (in terms of great-circle distance) grid on lon=0 is also equidistant in the latitude (difference in latitude being equal to the difference in distance over the radius of the sphere).

换句话说,如果您固定两个纬度lat1lat2,并且对于特定的经度lon(lat1, lon)(lat2, lon)向西移动1公里,则这些新获得的点将赢得没有相同的经度...

In other words, if you fix two latitudes lat1, lat2 and for a particular longitude lon move from (lat1, lon), (lat2, lon) 1km in, say, westward direction, then these newly obtained points won't have the same longitude...

我不确定您要达到的目标,但是如果目标是获得彼此之间不太接近的代表点,那么

I am not fully sure what you are trying to achieve but if the goal is to obtain some representative points not too close to each other, then perhaps hierarchical clustering in terms of the great-circle distance could provide reasonable results...

作为一种近似的解决方法,您可以通过选择除(0, 0)之外的另一个参考点来避免出现这种情况-新参考点不应与您要描述的区域相距太远(类似于底部" -感兴趣的区域的左"角).如果整个感兴趣的区域都没有覆盖全球的大部分地区(大范围的纬度),那么差异将非常小,因此它们可能几乎不会在GoogleMaps可视化中显示...

As an approximative workaround, you could get most likely away by choosing another reference point than (0, 0) - the new reference point shouldn't be too far away from the area that you are trying to describe (something like a "bottom-left" corner of the area of interest). If the entire area of interest doesn't cover a significant part of the globe (large span of latitudes) then the discrepancies will be quite small so that they will be probably almost invisible in the GoogleMaps visualization...

因此,如果您对丹麦感兴趣(根据屏幕截图判断),则可能会执行以下操作:

So if you are interested in Denmark (judging by the screenshots), then something like the following might work:

lat_ref, lon_ref = 53.637976, 6.694138

_,_, lon_dist = wgs84_geod.inv(lon_ref,lat_ref, lon, 0)
_,_, lat_dist = wgs84_geod.inv(lon_ref,lat_ref, 0, lat)

lat_km_dist = round(lat_dist/1000)*1000 #to nearest km and back to meters
lon_km_dist = round(lon_dist/1000)*1000


_, km_lat, _ = wgs84_geod.fwd(lon_ref,lat_ref,  0, lat_km_dist)
km_lon, _, _ = wgs84_geod.fwd(lon_ref,lat_ref, 90, lon_km_dist)

这篇关于将纬度,经度转换为距赤道的距离(以公里为单位),然后四舍五入为最接近的公里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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