Use for questions about the simplekml Python module used for creating KML files.
simplekml is a Python library for creating Keyhole Markup Language (KML) (or kmz) files. It was designed to hide to the complex details of KML with a simple API that follows the basic structure of KML. If you have a simple understanding of the structure of KML, then simplekml is easy to run with and create usable KML.
Flat learning curve:
Concise, readable and expressive syntax, easy to learn for python developers
Hello World
import simplekml
kml = simplekml.Kml()
kml.newpoint(name="Hello", coords=[(18.432314,-33.988862)]) # lon, lat, optional height
kml.save("botanicalgarden.kml")
This is what is generated:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2"
xmlns:gx="http://www.google.com/kml/ext/2.2">
<Document id="1">
<Placemark id="3">
<name>Hello</name>
<Point id="2">
<coordinates>18.432314,-33.988862,0.0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
Saving a KML document
Simply call kml.save(“pathtomyfile.kml”) passing a path to the file you want to create. Alternatively you can call kml.savekmz(“pathtomyfile.kmz”) to save the KML as a KMZ, or even kml.kml() to get the KML as a string.
Asking Questions:
- Before asking the question, make sure you have gone through the Getting Started introduction and Tutorials. It covers all the basic functionality of simplekml.