animation - How to make a flight path projection if possible in Python? -


i have latitude, longitude , altitude data , want make plot such in image below using python. map can left out, unnecessary. enter image description here

i have tried using mplot3d polygon plot tutorial can't figure out how have varying x , y values such not straight line. ideas?

it seems easiest way use google earth.

now there 2 ways tackle this. first method simple if want static picture. second method allows animation of flight path. both explained in answer.

method 1

using following python code have made kml file allows me create static visualization.

f = open('flight.kml', 'w')  #writing kml file. f.write("<?xml version='1.0' encoding='utf-8'?>\n") f.write("<kml xmlns='http://earth.google.com/kml/2.2'>\n") f.write("<document>\n") f.write("<placemark>\n") f.write("   <name>flight</name>\n") f.write("   <linestring>\n") f.write("       <extrude>1</extrude>\n") f.write("       <altitudemode>absolute</altitudemode>\n") f.write("       <coordinates>\n") in range(0,len(data['altitude']),10):  #here skip data     f.write("        "+str(data['lon_gps'][i]) + ","+ str(data['lat_gps'][i]) + "," + str(data['altitude'][i]) +"\n")     f.write("       </coordinates>\n") f.write("   </linestring>\n") f.write("</placemark>\n") f.write("</document>") f.write("</kml>\n") f.close() 

the code results in kml file in general looks this:

<?xml version='1.0' encoding='utf-8'?> <kml xmlns='http://earth.google.com/kml/2.2'> <document> <placemark>    <name>flight</name>    <linestring>        <extrude>1</extrude>        <altitudemode>absolute</altitudemode>        <coordinates>        54.321976,-4.90948,39232.0        54.320946,-4.90621,39232.0        ...        ...        52.329865,4.71601,0        52.329693,4.71619,0        </coordinates>    </linestring> </placemark> </document></kml> 

once *.kml file made using code above, in google earth 1 can import using file, import... google earth automatically displays image see below.

result

method 2

i figured out how animate flight. solution found split single <placemark> static answer several placemarks. adding <timespan> info each placemark allows animation take place. in order same visual had have beginning coordinates , end coordinates each placemark in order create proper <linestring>. result can found in video. video created using record tour button in google earth

f = open(fname+'.kml', 'w')  #writing kml file. f.write("<?xml version='1.0' encoding='utf-8'?>\n") f.write("<kml xmlns='http://earth.google.com/kml/2.2'>\n") f.write("<document>\n") f.write("   <name>flight</name>\n") in range(1,len(data['altitude'])):             f.write("<placemark>\n")      f.write("        <timespan>\n          <begin>" + '2015-12-02t%02i:%02i:%02iz' % (data['utc_hour'][i], data['utc_min'][i], data['utc_sec'][i]) + "</begin>\n        </timespan>\n")             f.write("   <linestring>\n")     f.write("       <extrude>1</extrude>\n")     f.write("       <altitudemode>absolute</altitudemode>\n")     f.write("        <coordinates>" +str(data['lon_gps'][i-1]) + ","+ str(data['lat_gps'][i-1]) + "," + str(data['altitude'][i-1]) + " "  +str(data['lon_gps'][i]) + ","+ str(data['lat_gps'][i]) + "," + str(data['altitude'][i]) +"</coordinates>\n")         f.write("   </linestring>\n")         f.write("</placemark>\n")  f.write("</document>") f.write("</kml>\n") f.close() 

the resulting kml file looks this:

<?xml version='1.0' encoding='utf-8'?> <kml xmlns='http://earth.google.com/kml/2.2'> <document>    <name>a332_conventional</name> <placemark>         <timespan>           <begin>2015-12-02t08:45:13z</begin>         </timespan>    <linestring>        <extrude>1</extrude>        <altitudemode>absolute</altitudemode>         <coordinates>-0.85058,53.338535,39200 -0.81538,53.332012,39200</coordinates>    </linestring> </placemark> ... ... <placemark>         <timespan>           <begin>2015-12-02t09:27:03z</begin>         </timespan>    <linestring>        <extrude>1</extrude>        <altitudemode>absolute</altitudemode>         <coordinates>4.71361,52.331066,0 4.71498,52.330379,0</coordinates>    </linestring> </placemark> </document></kml> 

Comments