【问题标题】:Python convert x,y data to latitude & longitude dataPython 将 x,y 数据转换为纬度和经度数据
【发布时间】:2018-07-03 13:24:53
【问题描述】:

此代码是一个函数,然后通过带有 if 语句的 for 循环运行它(为简洁起见,不包括在内,但基本上它允许我按机器和位置分隔一些工厂输出数据)。该函数旨在转换从已知纬度和经度位置以米为单位给出的 x 和 y 数据,并将其转换为新的经度和经度。我使用毕达哥拉斯和我在 SO 上找到的公式来做到这一点。

它可以正常工作,但数学运算失败,因为它或多或少地为输出增加了经度。它应该生成与参考位置非常相似的数据,因为它与参考位置的距离不会超过大约 50 米。

这里是 JSON 的一部分,从中获取数据以引起兴趣

"id": "b4994c877c9c",
"name": "forklift_0001",  <---forklift data used in IF statement
"areaId": "Tracking001",
"areaName": "hall_1",
"color": "#FF0000",
"coordinateSystemId": "CoordSys001",
"coordinateSystemName": null,
"covarianceMatrix": [
    0.47,
    0.06,
    0.06,
    0.61
],
"position": [
    33.86,    <---position data converted from known lat/long, X then Y.
    33.07,
    2.15
   ],
    "positionAccuracy": 0.36,
    "positionTS": 1489363199493,
    "smoothedPosition": [
        33.96,
        33.13,
        2.15

这是代码

import json
import pprint
import time
import math

file_list = ['13_01.json']

output_nr = 1

def positionToLatLon( position ):
    posx = position[0]
    posy = position[1]
    R = 6371 #Radius of the Earth
    brng = 1.57 #Bearing is 90 degrees converted to radians.
    d = math.sqrt((posx*posx) + (posy*posy)) #Distance in km from the lat/long  #Pythagoras formula
    lat1 = math.radians(40.477719)#reference lat point converted to radians
    lon1 = math.radians(16.941589)#reference long point converted to radians
    lat2 = math.asin(math.sin(lat1)*math.cos(d/R) + math.cos(lat1)*math.sin(d/R)*math.cos(brng))
    lon2 = lon1 + math.atan2(math.sin(brng)*math.sin(d/R)*math.cos(lat1),
    math.cos(d/R)-math.sin(lat1)*math.sin(lat2))
    lat2 = math.degrees(lat2)
    lon2 = math.degrees(lon2)
    result = []
    result.append(lat2)
    result.append(lon2)
    return result

所以它运行时没有任何错误,但输出不正确,它或多或少地增加了一个经度,因此将整个结果向东移动了大约 60m,使得分析变得不好,我不明白为什么。

我寻找了一个不同的公式,但没有运气,而且我的数学还不够好,无法判断我是否使用了不正确的三角函数或其他东西。

感谢所有帮助。

【问题讨论】:

  • 你能帮我告诉我position 输入是什么吗?那是您的 json 中的 "position" 键吗?你能告诉我调试这个的预期输出是什么吗?
  • 60nm 是 60 纳米。你肯定不是这个意思。但是——你是什么意思?此外,地球不是平坦的,因此不清楚您为什么要尝试使用勾股定理来计算地球表面上点之间的距离。
  • 您需要注意用于原点坐标变换的参数(即哪些投影)并准确复制它们。不同的投影很容易导致超过100米的差异。也许您可以使用gis.stackexchange.com/questions/78838/… 之类的东西来检查您的结果?
  • 1.是的,位置输入来自 JSON。预期的输出是再往东 1 度经度。 2. 60nm是60海里,纬度的基本单位。地球是圆的,数学应该是所有的。毕达哥拉斯计算与原点的距离,然后径向数学允许曲率(如果它是正确的数学)
  • 单位看起来很混乱。您说距离以米为单位,但您的代码似乎将它们视为公里。如果距离以米为单位,那么如此小的数字会被 glib 估计所淹没,例如 R = 63711.57 for math.pi/2。如果它们以公里为单位,那么在计算距离时忽略地球的曲率是不合理的,无论如何,说叉车距离已知位置 33.86 公里似乎不是一种非常明智的定位机器的方法一个工厂。如果您将问题设为minimal reproducible example 并说出预期的输出结果会有所帮助。

标签: python python-3.x math geolocation trigonometry


【解决方案1】:

将 brng = 1.57 更改为 brng = (math.pi/2)。这不是一个合适的估计,并且可能是您的一些错误的来源,如果不是全部的话

【讨论】:

    猜你喜欢
    • 2020-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-07
    相关资源
    最近更新 更多