簡體   English   中英

如何將度分秒轉換為十進制度(python/skyfield)

[英]how to convert degrees minutes seconds to decimal degrees (python/skyfield)

我想使用以下代碼以十進制提取衛星(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)

output 是一個字符串: -45deg 44' 13.5"

將其轉換為以下內容的最簡單方法是什么: -77.0089°

令人高興的是, latitudelongitude對象不是簡單的字符串,而是花哨的角度對象,它們僅將自身打印為 3 部分字符串,以便在屏幕上輕松閱讀。 您可以通過向 Python 索取他們的文檔來了解有關它們的更多信息。 在循環結束時,嘗試添加:

help(subpoint.latitude)

Angle class 的文檔將會出現。 您也可以在 web 上找到它:

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

您將需要使用屬性 degree ,它將degrees表示為浮點數。 將程序中的打印調用更改為:

print(subpoint.latitude.degrees)
print('\n')
print(subpoint.longitude.degrees)

嘗試這個

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)

Output:

48.522305555555555° 133.80061111111112°
48.49586111111111° 133.89988888888888°
48.46933333333334° 133.99902777777777°
48.44269444444444° 134.09808333333334°
48.416° 134.19702777777778°

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM