【问题标题】:Converting hddd° mm.mm′ to decimal degrees将 hddd° mm.mm' 转换为十进制度
【发布时间】:2020-11-19 12:52:43
【问题描述】:

我通过附加到电子邮件的 HTML 文档获取数据(不要问为什么...)。我需要从这个文件中读取 GPS 坐标,并想用 OSM 生成一条路线。将 GPS 坐标作为字符串获取没有问题,但我真的很难将它们形成 OSM 可以使用的东西。

GPS 坐标如下所示:N53°09.20 E009°11.82,分割不是问题,但我需要将它们形成正常的纬度和经度,例如 (53.119897, 7.944012)。

有没有人遇到同样的问题或者有我可以使用的库?

【问题讨论】:

  • 坐标是度、分、秒吗?通常格式为N53°09’20” E009°11’82”
  • Here !简短回答:在谷歌 python 角度到地理编码
  • 别忘了:WSG84 和 UTM 的计算方式不同。

标签: python maps gis openstreetmap latitude-longitude


【解决方案1】:

以下代码可用于将您提供的格式的度、分和秒转换为十进制经度和纬度:

import re

coords = "N53°09.20 E009°11.82"
regex = "N(\d+)°(\d+)\.(\d+) E(\d+)°(\d+)\.(\d+)"

match = re.split(regex, coords)

x = int(match[1]) + (int(match[2]) / 60) + (int(match[3]) / 3600)

y = int(match[4]) + (int(match[5]) / 60) + (int(match[6]) / 3600)

print("%f, %f" %(x, y))

输出:

53.155556, 9.206111

如果你的坐标只有度数和小数分,那么代码可以稍微修改一下,如下图:

import re

coords = "N53°09.20 E009°11.82"
regex = "N(\d+)°(\d+)\.(\d+) E(\d+)°(\d+)\.(\d+)"

match = re.split(regex, coords)

x = int(match[1]) + ((int(match[2]) + (int(match[3]) / 100)) / 60)

y = int(match[4]) + ((int(match[5]) + (int(match[6]) / 100)) / 60)


print("%f, %f" %(x, y))

输出:

53.153333, 9.197000

【讨论】:

  • 第二部分得到了完全想要的输出,谢谢!
  • 太好了,很高兴我能帮上忙。
猜你喜欢
  • 2013-10-27
  • 2021-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-03
  • 1970-01-01
  • 2015-01-09
  • 1970-01-01
相关资源
最近更新 更多