Questions tagged [pykml]

Use for questions about the pyKML Python module used for creating, parsing, manipulating, and validating KML files.

pyKML is a Python package for creating, parsing, manipulating, and validating KML, a language for encoding and annotating geographic data.

pyKML is based on the lxml.objectify API which provides a Pythonic API for working with XML documents. pyKML adds additional functionality specific to the KML language.

Flat learning curve:

Concise, readable and expressive syntax, easy to learn for developers

Hello World

Example code to create a KML object then output it to a file.

from pykml.factory import KML_ElementMaker as KML
from lxml import etree
 
kml = KML.Placemark(
   KML.name("Hello World!"),
   KML.Point(
     KML.coordinates("-64.5253,18.4607")
   )
)

with open('hello.kml', 'wb') as output:
   output.write(etree.tostring(kml, pretty_print=True, xml_declaration = True)) 

This is what is generated:

<?xml version='1.0' encoding='UTF-8'?>
<Placemark xmlns="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gx="http://www.google.com/kml/ext/2.2">
  <name>Hello World!</name>
  <Point>
    <coordinates>-64.5253,18.4607</coordinates>
  </Point>
</Placemark>

Asking Questions:

  • Before asking the question, make sure you have gone through the Examples and Tutorials. It covers all the basic functionality of pyKML.

Useful Canonicals:

35 questions
10
votes
1 answer

Inspect and Parse KML with pyKML

similar to this: Extract Coordinates from KML BatchGeo File with Python But I want to know how to inspect the data object, as well as how to iterate it, and parse all the Placemark to get the coordinates. The below is the how the KML looks like, and…
resting
  • 16,287
  • 16
  • 59
  • 90
10
votes
1 answer

Using pyKML to parse KML Document

I'm using the pyKML module for extracting coordinates from a given KML file. My Python code is as follows: from pykml import parser fileobject = parser.fromstring(open('MapSource.kml', 'r').read()) root =…
Newtt
  • 6,050
  • 13
  • 68
  • 106
7
votes
2 answers

Extract Coordinates from KML BatchGeo File with Python

I've uploaded some addresses to BatchGeo and downloaded the resulting KML file from which I want to extract the coordinates. I managed to prettify the jumbled text file online here, but I don't know how to parse it to extract the co-ordinates.…
eamon1234
  • 1,555
  • 3
  • 19
  • 38
4
votes
2 answers

Adding extended data to placemarks in python with pykml

I have uploaded some addresses to batchgeo along with several columns of data. I've downloaded the kml file which then has the coordiantes. The data structure is the following:
eamon1234
  • 1,555
  • 3
  • 19
  • 38
3
votes
2 answers

Write KML file from another

I'm trying to: - read a KML file - remove the Placemark element if name = 'ZONE' - write a new KML file without the element This is my code: from pykml import parser kml_file_path = '../Source/Lombardia.kml' removeList = list() with…
xCloudx8
  • 681
  • 8
  • 21
3
votes
2 answers

Read kml file with multiple placemarks in pykml

In pykml, I can read the first placemark in a file using the following code: with open(filename) as f: pm = parser.parse(f).getroot().Document.Folder print "got :" print pm.Placemark.LineString.coordinates How can I read multiple…
Catherine Holloway
  • 739
  • 1
  • 7
  • 20
3
votes
1 answer

Modify Map Layers with Python & PyKML

I am starting my first major Python/Python Scapy project and I need some guidance. I have found resources like PyKML and Google Earth COM API but I do not know which will be best used to implement my idea... I basically want to modify points in a…
pyRabbit
  • 803
  • 1
  • 9
  • 33
2
votes
0 answers

Is there a way to install pykml with conda and python 3.7?

If I try to install pykml with conda I got the following conflict: Specifications: pykml -> python[version='2.7.|3.4.|3.5.|3.6.|<3'] Your python: python=3.7 My question is now if there exist a way to install pykml in python3.7 and to avoid…
Woodz
  • 161
  • 2
  • 13
2
votes
1 answer

Syntax error when importing pykml.factory

So I am trying to use pyKML to create a KML file for google earth however when I try and import the module, I get the following: from pykml.factory import KML_ElementMaker as KML Traceback (most recent call last): File…
2
votes
1 answer

KML parsing child elements using django

I am trying to parse a kml file using django. I am using pyKML Parser Module. I have completed the following steps. root = parser.fromstring(open('myfile.kml').read()) The content of the file is: t1
user4330520
2
votes
1 answer

Plotting gridded data using KML

We are beginning a project to visualize the results of a finite volume (FV) calculation using Google Earth. The FV data is essentially 2d (lat/long) data consisting of a Cartesian array of values (sea surface height, for example). Each value…
Donna
  • 1,390
  • 1
  • 14
  • 30
2
votes
1 answer

Install pykml Python module in Windows 7 (64bits)

I am new into Python, so maybe my questions is stupid, but I am not able to install pykml module. Visiting its website, there are no Windows instructions for installing. Anyway I tried installing easy_install, and that doesn't work either. Since…
Roman Rdgz
  • 12,836
  • 41
  • 131
  • 207
1
vote
1 answer

How to access object parameters using pykml in a KML file

I have a python script that opens kml file and prase it to access specific elements inside of it, I have easily managed to access the data that lies inside every ,but I still need to access the id attribute inside every tag.. , here is an example…
Ahmed Wagdi
  • 3,913
  • 10
  • 50
  • 116
1
vote
1 answer

Can I embed an image into KML data generated by pykml?

I have a webserver with some icons I use for the KML points. Currently, each KML point references the Icon with and tags to the location of the image in the webserver. Thus, when viewing the data in Google Earth, the points have the custom icons…
Adrian
  • 13
  • 8
1
vote
1 answer

How to extract a LineString element color from a GE kml by using lmxl or pykml?

The GE kml file below do not make a elements color identification directly within the html code. How can I extract them in a csv file along with the name and its coordinates with a python extension. I already got the name and the coordinates but the…
apenzin
  • 13
  • 3
1
2 3