Over a million developers have joined DZone.

KML Utility Class

·

__author__ = "Jon Goodall  - http://www.duke.edu/~jgl34"
__version__ = "0.0.1"
__license__ = ""
__copyright__ =""

class KML_File:
    "For creating KML files used for Google Earth"
    def __init__(self, filepath):
        self.filepath = filepath
        "adds the kml header to a file (includes a default style)"
        file = open(filepath,"w")
        file.write(
        "\n"\
        "\n"\
        "\n"\
        "\n")
        file.close()

    def close(self):
        file = open(self.filepath,"a")
        file.write(
        "\n"\
        "")
        file.close()
        
    def open_folder(self, name):
        file = open(self.filepath,"a")
        file.write(
        "\n"\
        "  " + name + "\n")
        file.close()

    def close_folder(self):
        file = open(self.filepath,"a")
        file.write(
        "\n")
        file.close()
        
    def add_placemarker(self, latitude, longitude, altitude = 0.0, description = " ", name = " ", range = 6000, tilt = 45, heading = 0):
        "adds the point to a kml file"
        file = open(self.filepath,"a")
        file.write(
        "\n"\
        "  " + description + "\n"\
        "  " + name + "\n"\
        "  #normalPlaceMarker" + 
        "  \n"\
        "    " + str(longitude) + "\n"\
        "    " + str(latitude) + "\n"\
        "    " + str(range) + "\n"\
        "    " + str(tilt) + "\n"\
        "    " + str(heading) + "\n"\
        "  \n"\
        "  0\n"\
        "   \n"\
        "    1\n"\
        "    relativeToGround\n"\
        "    " + str(longitude) + "," + str(latitude) +", " +  str(altitude) + "\n"\
        "   \n"\
        " \n")
        file.close()
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}