Questions tagged [simplekml]

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 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.

Useful Canonicals:

49 questions
-1
votes
1 answer

Splitting KML file per placemark

I want to split kml file per placemark and save it as separate kml file, the code creates separate files but includes all previous placemarks in the file eg: Grid3 holds the data for Grid 1 & 2 , Grid 5 hold all previous and so on. Can someone…
Yasir
  • 13
  • 4
-1
votes
1 answer

Python convert KML to image file

Looking for some guidance on how to convert a KML file to an image file showing simple polygons of the GPS data held in the file? I've been looking at ways to do this via python using mapnik and simplekml but I'm unsure if this is the correct usage…
Grimlockz
  • 2,541
  • 7
  • 31
  • 38
-1
votes
2 answers

How can I call a simplekml module object?

I'm new to programming and I can't able to run this code it often shows an error like module object is not callable. Can anyone sort this out for me? import simplekml kml = simplekml.kml() #what's wrong…
-1
votes
1 answer

Python SimpleKML: Parsing JSON object to string for KML generation

I am looping through the amount of IP addresses in a traceroute and getting the geo-locational data from ip-api.com, I have then added the data that has been passed back into a variable called info. def toKML(iplist,namelist): kml =…
uvZ_
  • 13
  • 4
1 2 3
4