using the code below, and using pyephem and fastkml, I'd like to extract a ground track of a satellite from a TLE. The code looks as follows:
import numpy as np
import ephem
import datetime as dt
from fastkml import kml
from shapely.geometry import Point, LineString, Polygon
name = "ISS (ZARYA)"
line1 = "1 25544U 98067A 16018.27038796 .00010095 00000-0 15715-3 0 9995"
line2 = "2 25544 51.6427 90.6544 0006335 30.9473 76.2262 15.54535921981506"
tle_rec = ephem.readtle(name, line1, line2)
start_dt = dt.datetime.today()
intervall = dt.timedelta(minutes=1)
timelist = []
for i in range(100):
timelist.append(start_dt + i*intervall)
positions = []
for t in timelist:
tle_rec.compute(t)
positions.append((tle_rec.sublong,tle_rec.sublat,tle_rec.elevation))
k = kml.KML()
ns = '{http://www.opengis.net/kml/2.2}'
p = kml.Placemark(ns, 'Sattrack', 'Test', '100 Minute Track')
p.geometry = LineString(positions)#, tesselate=1,altitudemode="absolute")
k.append(p)
with open("test.kml", 'w') as kmlfile:
kmlfile.write(k.to_string())
Sadly, when I load the kml into Google Earth, the track looks as follows:
Any ideas where this goes wrong?
Your ground track is a loop around the position 0°N (on the Equator) and 0°E (directly south of Greenwich, near the Gulf of Guinea). This suggests that you are using angles expressed in radians, which can reach at most a value of about 6.2, and passing them to mapping software which reads them as degrees.
You should try converting them to degrees first:
positions.append((tle_rec.sublong / ephem.degree,
tle_rec.sublat / ephem.degree,
tle_rec.elevation))