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
vote
1 answer

Creating a file and returning it to Django in a view

I am trying to build a KML file on the fly for a user to download. I am playing with a KML library in python to produce and save KMLs but I want to return the file as ad ownload. Essentially if a user in my app clicks a link bam the KML is…
Codejoy
  • 3,722
  • 13
  • 59
  • 99
1
vote
1 answer

Python SimpleKML newpoint coordinates substitution

Using the python SimpleKML library and having problems substituting in my point (coordinate) values. Here's the code example from the website: import simplekml kml = simplekml.Kml() pnt = kml.newpoint(name='A Point') pnt.coords = [(1.0,…
Kenny Powers
  • 1,254
  • 2
  • 15
  • 25
1
vote
1 answer

Change style of a single point when sharedstyle is used in simplekml

I'm using simplekml to plot some data. As I can have a lot of points I'm using sharedstyle, but the problem is that I can't any style paraneter between every point (as the icon scale or the balloosstyle text). So, I have my sharedstyle kml =…
Pablo V.
  • 324
  • 2
  • 16
1
vote
2 answers

UnicodeEncodeError using python simplekml

I'm trying to create a kml from a xlsx file, but when xlsx contains utf-8 it's not working. I saw simplekml documentation and it's marked as solved, but I can't make it work. I've tried setting the encode to ascii, also used django's smart_str and…
Fernando Freitas Alves
  • 3,709
  • 3
  • 26
  • 45
0
votes
1 answer

Not able to overwrite kml file

I generate KML files on-the-fly.After generating, I call Google maps like this : http://maps.google.com/maps?q=http://:8081//.kml . The name of the file I use is based on the lat/long of the starting location entered by…
crazyaboutliv
  • 3,029
  • 9
  • 33
  • 50
0
votes
2 answers

how to change shape color using `simple_kml` in python

I'm using simple_kml library to generate a kml file with data sent from drawing manager on google Maps using Javascript, everything goes fine except the color of the shape .. the color send in this format #ec0909, and here is how am trying to add it…
Ahmed Wagdi
  • 3,913
  • 10
  • 50
  • 116
0
votes
2 answers

How to create a Wind Rose in KML format (google earth) using Python

I need to create a Wind Rose KML file to be opened in google earth with as (similar to) the following pictures. I can create wind roses using windrose python module, like this one: And I know how to create KML points and lines in python using…
Lucho
  • 221
  • 1
  • 6
0
votes
1 answer

Issue reproducing "Create a kml in python that has both points and lines" post

I'm trying to replicate a post I came across in the link below and had an error message come up I'm a bit unsure how to resolve: Link to Prior Post I'm trying to replicate I'm getting an error on the following line: coord = (row[5], row[6]) # lon,…
Geno
  • 29
  • 7
0
votes
0 answers

Create CSV2KML file to plot paths with sets of coordinates in CSV, using Python

I have the following csv file with Site A and Site B coordinates. I would like to plot a path between Site A and Site B using Python. The following is csv file. Site A Site B Site A Lat Long Site B Lat Long PRGR 53.906969°…
Kourosh
  • 51
  • 9
0
votes
1 answer

python's simplekml doesn't output "Alias" tag

I'm writing a simple script using simplekml 1.3.5 (it's a Python liblary for generating KML) for climate data visualization. import simplekml kml_filename ='sample.kml' kml = simplekml.Kml(open=1) model =…
Regulus
  • 11
  • 4
0
votes
1 answer

Google Maps changing placemark icon solely based on styleUrl string syntax

I've written a simple script in python that converts a CSV file to a KML file using the simplekml package. It colors my points based on one of my data values. My problem is this: I’m trying to use the smallest icon possible because my placemarks are…
Topo
  • 1
  • 1
0
votes
2 answers

How do I add a height to a point in python3 simplekml?

I am trying to plot a point for an aircraft at about 1000m. The docs say that I can add it after the coords but it is not working. I am using Jupyter but here is my code. When I add no data after the coords it puts the point on the ground. When I…
0
votes
1 answer

In Python, how do you insert an additional field in an created csv file that has elseif conditions on the field contents based on results of query?

Here is the python code that takes the data from my query and packages it to go into a csv file. ... col_headers = [ i[0] for i in cursor.description ] rows = [ list(i) for i in cursor.fetchall()] df = pd.DataFrame(rows,…
AntwonA
  • 11
  • 2
0
votes
1 answer

Iterating through directory for all csv files and creating kml for each individual(csv) file and save using file name

import csv import simplekml import pandas as pd import glob frame = pd.DataFrame() filelist=glob.glob('/Users/germanportes/Documents/Status_Report/Telework_training/Anomaly_6/files/*.csv') kml = simplekml.Kml() for file in filelist: a6…
0
votes
3 answers

Error while creating KML from a dict using simplekml

I'm creating kml using the library simplekml. When creating a single one, it works like a charm, but when trying to create one kml per dict entry, returns an error I could not locate. The data have this kind of format: {12: {900: [(-5.4529673,…
user9264168