Simple KML Creator
simplekml is a Python package designed for generating KML (Keyhole Markup Language) and KMZ files with minimal effort. It simplifies the creation of KML documents, folders, points, linestrings, and polygons without requiring in-depth knowledge of the KML standard itself. The current version is 1.3.6. Release cadence is infrequent, with the last update in 2021, and prior updates in 2020 and 2018.
Warnings
- gotcha Coordinates order: simplekml expects coordinates in (longitude, latitude, optional height) order. This is a common source of error as many other GIS contexts use (latitude, longitude).
- gotcha Polygons with multiple inner boundaries may not render correctly in Google Maps for Android. While Google Earth is more forgiving, Google Maps for Android (especially with older SDK utility libraries) may require multiple `<innerBoundaryIs>` tags, each with a single `<LinearRing>`, rather than simplekml's output of multiple `LinearRing` elements within a single `<innerBoundaryIs>` tag.
- gotcha For complex GPS track data (e.g., time-series points), KML is not the most suitable format, and simplekml does not directly support advanced KML extensions like `gx:Track`. Consider using the GPX format and a library like `gpxpy` for such use cases, as GPX is better designed for tracks.
Install
-
pip install simplekml
Imports
- Kml
from simplekml import Kml
- simplekml
import simplekml
Quickstart
import simplekml
kml = simplekml.Kml()
kml.newpoint(name="Kirstenbosch", coords=[(18.432314, -33.988862)]) # Longitude, Latitude, optional height
kml.save("botanicalgarden.kml")