Python GPS 半径/距离

Python GPS Radius / Distance

我在 "file.txt" 中有一个带有 GPS 坐标的列表,其中的格式为 "latitude, longitude"。我将尝试用我尝试学习的语言 Python 来解释我想要的示例或代码。

GPS = 当前位置 + RADIUS / MARGIN = 0.9(900 米)

当前 GPS 位置将是 "collected" 来自“/dev/ttyS0”中的串行,使用连接到 Raspberry Pi3 ( Raspbian ) 的 GPS 模块。

我需要根据我在 "file.txt".

中的坐标列表知道我当前的位置(使用 900 米的半径/边距)是真还是假

file.txt

-34.61517, -58.38124
-34.61517, -58.38124
-34.61527, -58.38123
-34.61586, -58.38121
-34.61647, -58.38118
-34.61762, -58.38113
-34.61851, -58.38109
-34.61871, -58.38109
-34.61902, -58.38108
-34.61927, -58.38108
-34.61953, -58.38108
-34.61975, -58.38106
-34.61979, -58.38112
-34.6198, -58.38113
-34.61981, -58.38115
-34.61983, -58.38116
-34.61986, -58.38117
-34.61993, -58.38118
-34.62011, -58.38119
-34.62037, -58.38121
-34.62059, -58.38122
-34.62075, -58.38122
-34.6209, -58.38122
-34.62143, -58.38117
-34.62157, -58.38115
-34.62168, -58.38115
-34.6218, -58.38114
-34.62191, -58.38115
-34.62199, -58.38116
-34.62206, -58.38119
-34.62218, -58.38123
-34.62227, -58.38128
-34.62234, -58.38134
-34.62241, -58.3814
-34.62249, -58.38149
-34.62254, -58.38156
-34.62261, -58.38168
-34.62266, -58.38179
-34.62273, -58.38194
-34.62276, -58.38201
-34.62283, -58.38238
-34.62282, -58.38261
-34.62281, -58.38291
-34.62281, -58.38309
-34.62281, -58.38313
-34.62281, -58.3836
-34.62281, -58.38388
-34.62282, -58.38434
-34.62282, -58.38442
-34.62283, -58.3845
-34.62283, -58.38463
-34.62285, -58.38499
-34.62287, -58.3853
-34.6229, -58.38581
-34.62291, -58.38589
-34.62292, -58.38597
-34.62297, -58.38653
-34,623, -58,3868
-34.62303, -58.3871
-34,623, -58,38713
-34.62299, -58.38714
-34.62298, -58.38715
-34.62298, -58.38716
-34.62297, -58.38717
-34.62297, -58.38728
-34.62297, -58.38735
-34.62298, -58.38755
-34.62299, -58.3877
-34.62305, -58.38829
-34.62308, -58.38848
-34.6231, -58.38865
-34.62311, -58.38874
-34.62316, -58.3892
-34.62318, -58.38933

Sample Image 1

这在 Python 中可行吗? 提前致谢 (:

我不明白你想知道的是否正是这个。这个解决方案参考了问题"Given a point and my current position, is my distance from that point minor than a specific value?".

如果是这种情况并且距离足够小(小于 1 公里),您可以使用勾股定理:

distance = c*6371*180/pi*sqrt((currentPosition.lat - targetLat)**2 + 
                     (currentPosition.long - targetLong)**2)

其中 c 是您必须在您的区域中找到的系数(例如,在意大利它是 0.8,只需除以实际值 - 您可以使用 Google 地图获得它 - 根据您设置 c 的结果at 1), 6371 为地球半径,pi 为 3.14159;然后你可以将距离与你想要的最大距离进行比较

distance < maxDistance

在本例中,maxDistance 为 0.9 。

请注意,此公式是近似值,但是考虑到您处理的距离很近,它可能足够准确。如果距离较大,则应使用三角函数(例如,如果要比较两个不同大陆的两个点,则没有意义)。在那种情况下,这是您应该使用的公式 - 大圆公式:

distance = 6371*acos(sin(lat1)*sin(lat2)+cos(lat1)cos(lat2)cos(long1-long2))

其中 (lat1,long1) 和 (lat2,long2) 是您正在测量的两个点的球面坐标。然后像前面的表达式一样将距离和maxDistance进行比较,就大功告成了。

如果您想解决 txt 文件中一组点的问题,只需读取这些值并使用 for 循环或 for-each 遍历它们。

参考 https://en.wikipedia.org/wiki/Great-circle_distance 了解更多详情。