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
0
votes
1 answer

pycharm pykml import error

I am trying to run a pykml project on pycharm. I have installed pykml and xlml packages using easy_install command on OS X. However the lines from lxml import etree from pykml.parser import Schema from pykml.factory import KML_ElementMaker as…
emrahozkan
  • 193
  • 1
  • 3
  • 15
0
votes
2 answers

Python libraries needed to interact withPyKML. Need some guidance with libxml2 and libxslt

I am teaching myself Python, and thanks to the great help I am getting here when I am stuck with something, I am happy with my progress. I am working on a project that retrieves a bunch of records from several APIs, data mines addresses, extracts…
Luis Miguel
  • 5,057
  • 8
  • 42
  • 75
-1
votes
2 answers

I want to extract coordinates from KML file

I am trying to extract coordinates from kml file in python but it is giving me the error. below are my code and kml file. Code: from pykml import parser root = parser.fromstring(open('task_2_sensor.kml', 'r').read()) print…
-1
votes
1 answer

Replace coordinates in KML file with python3

I need to replace all coordinates in a KML file: 24.6206,58.0265,10 24.6218,58.0245,260 24.6234,58.0221,510 24.6257,58.0191,760 I tried in this way but root is empty at the end: from pykml import parser import…
seq16
  • 17
  • 4
-1
votes
2 answers

Parsing XML with Pykml

I have the following xml file I got from QGIS
sylar_80
  • 251
  • 3
  • 18
1 2
3