Export active flight track as .kml

Issue #158 resolved
Vladyslav Nenakhov created an issue

Dear mss developer,

right now it is possible to export the active flight track as .CSV file. Is it maybe possible to export the active flight track also as .kml file.

Benefit: It would open the possibility to load the flight track directly in google earth and give the option to check more details on the google map in respect to your flight.

In the attachment you can find different formats of a "test_flight1" track: .ftml - for mss .csv - as export from mss (with calculation from flight level to meters for .kml file) .kml - for google earth .txt - code of the kml file

the kml header could always look like in e.g. .txt file. It would be good if between <name> and </name> and <description> and </description> the given name of the flight track in mss could be inserted and the .kml file name also would have the name of the mss flight track.

For the coordinates in the .kml in respect to .csv file the flight level must be converted to meters + latitude and longitude must be exchanged by each other.

Note: in google earth the "test_flight1" track is in some areas below the earth surface.

Best regards Vlad

Comments (8)

  1. Joern Ungermann

    The envisioned way for this functionality would be to provide a "plugin" similar to those placed in mslib/plugins/io This functionality sounds useful and a "standard" plugin for this sounds reasonable. Would you be able to provide a draft for this?

  2. Vladyslav Nenakhov reporter

    I got last week 3 days crash course in Python from Andreas Hilboll. Python is very interesting and i want to learn more, but it will take some time until i can really go more deeper inside the language. I will give a try, but i guess in the end i will write a LabView program witch reads the .csv file and creates an .kml file.

  3. Joern Ungermann

    Just have a look at the plugins folder, please. Creating a KML export plugin should be very simple even with basic Python knowledge (at least that was the intention). If you take the text plugin as template (i guess importing is not necessary). You basically need only change the header, remove everything but lon/lat/altitude and write a footer. Please let me know if you have problems, I can be of assistance.

  4. Joern Ungermann

    This would be as starting point for you. I do not use KML or Google Earth, so I cannot really test this.

    def save_to_kml(filename, name, waypoints):
        if not filename:
            raise ValueError("filename to save flight track cannot be None")
        with open(filename, "w") as out_file:
            header = """<?xml version="1.0" encoding="UTF-8" ?>
    <kml xmlns="http://earth.google.com/kml/2.2">
    <Document>
    <name>{name}</name>
    <open>1</open>
    <description>MSS flight track export</description>
    <Style id="flighttrack">
    <LineStyle><color>ff000000</color><width>4</width></LineStyle><PolyStyle><color>FFF87217</color></PolyStyle></Style>
    <Placemark><name>HALO</name>
    <styleUrl>#flighttrack</styleUrl>
    <LineString>
    <tessellate>1</tessellate><altitudeMode>absolute</altitudeMode>
    <coordinates>
    """.format(name=name)
            line = "{lon:.3f},{lat:.3f},{alt:.3f}\n"
            footer = """</coordinates>
    </LineString></Placemark>
    </Document>
    </kml>"""
            out_file.write(header)
            for i, wp in enumerate(waypoints):
                lat = wp.lat
                lon = wp.lon
                lvl = wp.flightlevel
                alt = lvl * 100 * 0.3048
                out_file.write(line.format(lon=lon, lat=lat, alt=alt))
            out_file.write(footer)
    

    Put this in a location that you can import and activate the plugin in your JSON file.

    "export_plugins": {
        "KML": ["kml", "mslib.plugins.io.kml", "save_to_kml"]
    },
    

    I put the file into mslib/plugins/io, obviously. If it works, you can make a pull request, or I can add the final version to the code.

  5. Log in to comment