0

我想使用以下代码以十进制提取卫星(ISS)的坐标:

from skyfield.api import EarthSatellite, Topos, load
import time

line1 = '1 25544U 98067A   14020.93268519  .00009878  00000-0  18200-3 0  5082'
line2 = '2 25544  51.6498 109.4756 0003572  55.9686 274.8005 15.49815350868473'

satellite = EarthSatellite(line1, line2, name='ISS (ZARYA)')

while True:
    ts = load.timescale()
    t = ts.now()
    geometry = satellite.at(t)

    subpoint = geometry.subpoint()
    print(subpoint.latitude)
    print('\n')
    print(subpoint.longitude)
    time.sleep(1)

输出是一个字符串:-45deg 44' 13.5".

将其转换为以下内容的最简单方法是什么:-77.0089°

4

2 回答 2

1

令人高兴的是,这些对象latitudelongitude不是简单的字符串,而是花哨的角度对象,它们仅将自身打印为 3 部分字符串,以使它们易于在屏幕上阅读。您可以通过向 Python 索取他们的文档来了解更多关于它们的信息。在循环结束时,尝试添加:

help(subpoint.latitude)

Angle课程的文档将出现。你也可以在网上找到它:

https://rhodesmill.org/skyfield/api-units.html#skyfield.units.Angle

您将需要使用将degrees角度表示为浮点数的属性。将程序中的打印调用更改为:

print(subpoint.latitude.degrees)
print('\n')
print(subpoint.longitude.degrees)
于 2020-04-10T23:48:30.157 回答
0

尝试这个

from skyfield.api import EarthSatellite, Topos, load
import time
line1 = '1 25544U 98067A   14020.93268519  .00009878  00000-0  18200-3 0  5082'
line2 = '2 25544  51.6498 109.4756 0003572  55.9686 274.8005 15.49815350868473'

satellite = EarthSatellite(line1, line2, name='ISS (ZARYA)')

def convert(deg):
  d, m, s = str(deg).replace('deg', '').split(" ")
  ans = float(d) + (float(m.strip("'")) / 60) + (float(s.strip('"')) / 3600)
  return str(ans) + chr(176)

while True:
    ts = load.timescale()
    t = ts.now()
    geometry = satellite.at(t)

    subpoint = geometry.subpoint()
    lat = convert(subpoint.latitude)
    lng = convert(subpoint.longitude)
    print(lat, lng)
    time.sleep(1)

输出:

48.522305555555555° 133.80061111111112°
48.49586111111111° 133.89988888888888°
48.46933333333334° 133.99902777777777°
48.44269444444444° 134.09808333333334°
48.416° 134.19702777777778°
于 2020-04-10T08:16:30.053 回答