Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

KML Utility Class

DZone's Guide to

KML Utility Class

·
Free Resource

__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:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}