pykml / pykml Goto Github PK
View Code? Open in Web Editor NEWA Python package for creating and manipulating KML documents.
Home Page: https://pythonhosted.org/pykml/
License: BSD 3-Clause "New" or "Revised" License
A Python package for creating and manipulating KML documents.
Home Page: https://pythonhosted.org/pykml/
License: BSD 3-Clause "New" or "Revised" License
==== PyKML ===== PyKML is a Python package for authoring, parsing, and manipulating KML documents. It is based on the lxml library (http://codespeak.net/lxml/) which provides a Python API for working with XML documents. ------------ Dependencies ------------ * lxml (>=2.2.8, older versions not tested)
Add method that creates the child elements of gx:Track.
See: http://code.google.com/apis/kml/documentation/kmlreference.html#gxtrack
Original issue reported on code.google.com by [email protected]
on 3 Aug 2011 at 10:12
Hello, thanks for this utility! I'm trying to modify existing PhotoOverlay KMLs (changing altitude mode, value, and replacing the image's href
) with the following code (just an example):
with open("/mnt/d/dev/situated-views/data-in/kml-sessions/001ALA011001.kml") as f:
kml = parser.parse(f).getroot()
kml.PhotoOverlay.Camera.altitude = 100
print(etree.tostring(kml))
This succesfully changes the value, but it introduces xmlns:py="http://codespeak.net/lxml/objectify/pytype" py:pytype="int"
in the <altitude>
tag. I'm also unsure of how to overwrite the open kml or even save it as a new file. Although
with open("/mnt/d/dev/situated-views/data-in/kml-sessions/001ALA011001.kml", "r+") as f:
kml_str = f.read()
bytes = kml_str.encode('utf-8')
kml = parser.fromstring(bytes)
kml.PhotoOverlay.Camera.altitude = 100
new_kml = etree.tostring(kml).decode('utf-8')
f.seek(0)
f.write(str(new_kml))
f.truncate()
"works", it seems awfully overcomplicated and the resulting file is poorly formatted. What's the recommended way of opening a file, modifying its contents and overwriting it? And is it possible to avoid the introduction of the namespace URI in the changed tags? Thanks a million
How to best bridge between geometries in the many python geo libraries? e.g.
shapely, gdal-py, geodjango, geoalchemy, etc
It would be great to have examples of how to go between each of these and a
PyKML.
Original issue reported on code.google.com by [email protected]
on 3 Aug 2011 at 9:24
Add an example of parsing the KML output of Google's Fusion Tables, and
modifying the style.
Fusion Tables API:
http://code.google.com/apis/fusiontables/docs/developers_guide.html
Original issue reported on code.google.com by [email protected]
on 2 Aug 2011 at 9:24
Currently pyKML only validates against schemas documents that are stored
locally. It would be easier to keep up with schema definition changes if pyKML
could validate against a remote schema accessible via a URL.
Original issue reported on code.google.com by [email protected]
on 22 Sep 2011 at 6:40
Add example of using pyKML to display the results of a geocoding operation.
Original issue reported on code.google.com by [email protected]
on 3 Aug 2011 at 10:06
Describe the proposed enhancement...
http://www.eia.gov/cfapps/ipdbproject/iedindex3.cfm?tid=5&pid=5&aid=8&cid=region
s&syid=1980&eyid=2009&unit=MMTCD
Note: A URL of the an excel file of the data can be constructed by viewing the
javascript in the page source.
Original issue reported on code.google.com by [email protected]
on 29 Jan 2012 at 4:57
Generate text overlays automatically using the Google Charts API.
https://chart.googleapis.com/chart?chst=d_text_outline&chld=000000|36|h|ffffff|b
|Sample+first+line.|and+a+second+line!
http://chart.googleapis.com/chart?chst=d_simple_text_icon_above&chld=Single+line
+of+text|20|000000|medical|12|F88|FF0000
Original issue reported on code.google.com by [email protected]
on 23 Feb 2012 at 9:05
Add a function that removes any unused style and/or style maps.
Original issue reported on code.google.com by [email protected]
on 17 May 2011 at 12:55
Strip out all of the styling information.
Original issue reported on code.google.com by [email protected]
on 17 May 2011 at 12:56
It would be great to have a module that helped craft extended data for each of
the 3 types.
Original issue reported on code.google.com by [email protected]
on 3 Aug 2011 at 9:10
http://lxml.de/api/lxml.objectify.PyType-class.html
Original issue reported on code.google.com by [email protected]
on 6 Oct 2011 at 4:10
Add an example that demonstrates how to generate a tour based on data in an
Excel file.
Original issue reported on code.google.com by [email protected]
on 2 Aug 2011 at 9:19
[deleted issue]
Add and example of adding a time overlay (similar to mapthefallen.com)
Original issue reported on code.google.com by [email protected]
on 3 Aug 2011 at 9:57
Create an example python script that takes a KML folder of placemarks as an
input, and creates a tour of the placemarks.
Original issue reported on code.google.com by [email protected]
on 2 Aug 2011 at 9:26
What steps will reproduce the problem?
Parse some KML with <![CDATA[]]> without using a schema: parser.parse(f,
schema=None)
When writing the document back out to file, CDATA sections are lost, and all
characters are converted to HTML entities.
This doesn't happen when parsing with schema validation.
Can be rectified by modifying line 55+ of parse.py to this:
# without validation
parser = objectify.makeparser(strip_cdata=False)
return objectify.parse(fileobject, parser=parser)
Original issue reported on code.google.com by [email protected]
on 13 Oct 2011 at 11:21
Write a Python script that gathers statics of how many elements are used in a
KML file.
Original issue reported on code.google.com by [email protected]
on 2 Aug 2011 at 9:30
I want to read a mymaps .kml file that contains different layers with pykml. When exploring the .kml with Notepad++ i see 9 folders, but when I enter the document I just see one "Folder" in the document, that is the first "Folder" I see in Notepad ++, with name casa. How I get the 9 "Folders" or layers? Its possible with pykml? Thanks for your time.
import glob
from pykml import parser
import pandas as pd
with open(filename, encoding='utf-8') as f:
document = parser.parse(f).getroot().Document
It would be great to have a number of helpers for creating Balloon content. Or
maybe just examples.
e.g. Using the Google Charts API with
http://pygooglechart.slowchop.com/
Is there any extra glue that would help make this super easy to do?
In the following post, it looks like you can have extended data that is intern
passed to the charts API:
http://googlemapsapi.blogspot.com/2007/12/using-chart-api-in-kml-for-quick-data.
html
Original issue reported on code.google.com by [email protected]
on 3 Aug 2011 at 9:16
I just tried pip install pykml, and was disappointed to see that this no longer works. I get
...
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out. (read timeout=15)")': /packages/8f/16/276e16f024db5aca4c8891cecd56219a5a1e016fa356e858dfb04590b1d5/pykml-0.1.3.tar.gz
ERROR: Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/8f/16/276e16f024db5aca4c8891cecd56219a5a1e016fa356e858dfb04590b1d5/pykml-0.1.3.tar.gz (Caused by ReadTimeoutError("HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out. (read timeout=15)"))
Is anyone actively developing or maintaining PyKML? This is a fantastic package, and it would be great if someone wanted to at least maintain it for current releases of Python.
Work through a KML tour document, adding comments that state the time relative
to the start of the tour.
Original issue reported on code.google.com by [email protected]
on 2 Aug 2011 at 9:28
What steps will reproduce the problem?
1. Checkout source via hg
2. Setup virtual environment per
http://schwehr.org/blog/archives/2011-07.html#e2011-07-15T17_39_10.txt
3. easy_install pykml
4. cd pykml/src/examples/misc
5. python virtual_base_jump.py
What is the expected output? What do you see instead?
I can't figure out where kml_gx is.
$ python virtual_base_jump.py
Traceback (most recent call last):
File "virtual_base_jump.py", line 6, in <module>
from pykml.kml_gx import schema
ImportError: No module named kml_gx
(virt1)
What version of the product are you using? On what operating system?
I'm using hg clone and easy_install on July 15.
Please provide any additional information below.
If I am in the top level directory, I'm not finding any files except in the hg
store for gx...
find . | grep -i gx
./.hg/store/data/pykml/kml__gx
./.hg/store/data/pykml/kml__gx/____init____.py.i
./.hg/store/data/pykml/kml__gx/factory.py.i
./.hg/store/data/pykml/kml__gx/helpers.py.i
./.hg/store/data/pykml/kml__gx/parser.py.i
./.hg/store/data/pykml/kml__gx/schemas
./.hg/store/data/pykml/kml__gx/schemas/kml22gx.xsd.i
./.hg/store/data/pykml/kml__gx/test
./.hg/store/data/pykml/kml__gx/test/____init____.py.i
./.hg/store/data/pykml/kml__gx/test/test__factory.py.i
./.hg/store/data/pykml/kml__gx/test/test__parse.py.i
./.hg/store/data/pykml/kml__gx/test/testfiles
./.hg/store/data/pykml/kml__gx/test/testfiles/google__kml__developers__guide
./.hg/store/data/pykml/kml__gx/test/testfiles/google__kml__developers__guide/com
plete__tour__example.kml.i
./.hg/store/data/pykml/schemas/kml22gx.xsd.i
./.hg/store/data/src/pykml/schemas/kml22gx.xsd.i
./build/lib/pykml/schemas/kml22gx.xsd
./src/pykml/schemas/kml22gx.xsd
Original issue reported on code.google.com by [email protected]
on 16 Jul 2011 at 1:57
Create an example that uses pyKML to display the results of a time series of
WMS calls.
Original issue reported on code.google.com by [email protected]
on 3 Aug 2011 at 10:08
Given a <LookAt> element, determine the location of the camera.
Original issue reported on code.google.com by [email protected]
on 30 Aug 2011 at 9:10
What steps will reproduce the problem?
1. providing a version of pykml for mac osx
2.
3.
What is the expected output? What do you see instead?
What version of the product are you using? On what operating system?
mac osx 10.6 python 2.6
Please provide any additional information below.
Original issue reported on code.google.com by [email protected]
on 2 Jan 2013 at 8:04
Pykml corrupt cyrillic characters. Word "привет" its decode to Привет
How disable it?
Example script from Sean:
#!/usr/bin/python
from lxml import etree
from pykml.factory import KML_ElementMaker as KML
TEXT_ELEMENTS = ['description', 'text', 'linkDescription', 'displayName']
def getXmlWithCDATA(obj, cdata_elements):
# Convert Objectify document to lxml.etree (is there a better way?)
root = etree.fromstring(etree.tostring(etree.ElementTree(obj)))
#Create an xpath expression to search for all desired cdata elements
xpath = '|'.join(map(lambda tag: '//kml:' + tag, cdata_elements))
results = root.xpath(xpath, namespaces = {'kml': 'http://www.opengis.net/kml/2.2'})
for element in results:
element.text = etree.CDATA(element.text)
return root
kmlobj = KML.kml(
KML.Document(
KML.Placemark(
KML.name('foobar'),
KML.styleUrl('#big_label'),
KML.description('<html>'),
KML.text('<html>'),
KML.linkDescription('<html>'),
KML.displayName('<html>')
)
)
)
kmlobj_with_cdata = getXmlWithCDATA(kmlobj, TEXT_ELEMENTS)
print etree.tostring(kmlobj_with_cdata, pretty_print=True)
Original issue reported on code.google.com by [email protected]
on 22 Feb 2012 at 12:56
Create an example that demonstrates updates based on a real-time feed. See the
High Performance KML talk from Google I/O for a discussion of the technique
(http://www.youtube.com/watch?v=nIoWHlEEeNI).
Original issue reported on code.google.com by [email protected]
on 3 Aug 2011 at 10:04
Add an example that demonstrates how to generate placemarks based on data in a
csv file.
Original issue reported on code.google.com by [email protected]
on 21 Jul 2011 at 12:08
Create an example that takes a GeoTIFF file, projects the image to WGS84, and
adds it as a GroundOverlay. This can probably be accomplished using pyKML and
the GDAL Python bindings.
Original issue reported on code.google.com by [email protected]
on 3 Aug 2011 at 10:00
Hi
Is there a way to add coordinates to a linestring in an already existing KML
file?
Original issue reported on code.google.com by [email protected]
on 8 Jan 2015 at 12:46
Create an example that adds a legend overlay.
Original issue reported on code.google.com by [email protected]
on 2 Aug 2011 at 9:32
Use some xml tool to better localize problems with a document not matching a
schema.
Ugly solution... call xmllint command line program. Yuck
Better would be to figure out how to call something from lxml or libxml2.
Would be best to use lxml if at all possible to keep the dependencies down.
Additionally, is it possible to validate fragments of kml?
Original issue reported on code.google.com by [email protected]
on 3 Aug 2011 at 9:09
Add an example that demonstrates how to generate placemarks based on data in an
Excel document.
Original issue reported on code.google.com by [email protected]
on 2 Aug 2011 at 9:16
How ignore this errors?
Create an example that creates a gridded summary of point data (twitter feeds?).
Original issue reported on code.google.com by [email protected]
on 3 Aug 2011 at 10:02
Add a function that takes a pyKML document and returns a second pyKML document
without any temporal information.
Original issue reported on code.google.com by [email protected]
on 21 Jul 2011 at 12:07
Add a method for summarizing the time information in KML file (i.e. start,end)
Add a method for shifting (translating) time by a specified amount.
Add a method for scaling time by a specified ratio and origin.
Original issue reported on code.google.com by [email protected]
on 3 Aug 2011 at 9:55
Add an example that demonstrates how to generate a tour based on data in a csv
file.
Original issue reported on code.google.com by [email protected]
on 21 Jul 2011 at 12:13
Could you avoid using setuptools for the setup script? distutils is the
preferred module for this, and it's included in the stdlib. Not worth using
setuptools just for the lxml dependency, I'd think.
Original issue reported on code.google.com by [email protected]
on 18 Jan 2012 at 7:52
What steps will reproduce the problem?
It may be possible to leak local files or make network requests when processing
a malicious document, per
https://www.owasp.org/index.php/XML_External_Entity_%28XXE%29_Processing
The default options to the lxml parser are not suitable for use on untrusted
inputs, and pykml.parser does not expose them for reconfiguration.
See PoC/example below.
What is the expected output? What do you see instead?
parser.parse() should probably default to using a lxml.Parser instance with
resolve_entities=False (and maybe no_network=True) to avoid malicious entity
expansion.
http://lxml.de/parsing.html#parser-options details the available options.
What version of the product are you using? On what operating system?
OSX 10.9.1
Python 2.7.6 (MacPorts)
pykml==0.1.0
Please provide any additional information below.
# Simple PoC from OWASP sample document.
from lxml import etree
from pykml import parser
doc = parser.fromstring('<?xml version="1.0" encoding="UTF-8"?>'
'<!DOCTYPE foo [ <!ELEMENT foo ANY > '
'<!ENTITY xxe SYSTEM "file:///etc/passwd" >]>'
'<foo>&xxe;</foo>')
print etree.tostring(doc, pretty_print=True)
---
Mitigation:
I'm unaware of any KML documents that actually use entities, so just modifying
the parse/fromstring functions to use a parser with expand_entities disabled
may be sufficient.
An alternative may be to add new methods parse_safe() or add additional
optional kwargs to the existing methods to allow users to provide their own
Parser object, or set options on it.
If anything other than the first option, the docs should be updated with a
prominent warning about the risks of handling untrusted input without
precautions.
An example kml input that also passes kml22gx.xsd schema validation is attached.
Original issue reported on code.google.com by [email protected]
on 8 Feb 2014 at 2:26
Attachments:
Given a series of camera parameters, calculate intermediate camera positions
using splines.
Possibly useful refs:
http://code.activestate.com/recipes/457658-cubic-spline-interpolator/
http://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html#spline-inter
polation
http://en.literateprograms.org/Cubic_spline_(Python)
http://cairnarvon.rotahall.org/2009/07/05/quadratic-spline-interpolation/
Original issue reported on code.google.com by [email protected]
on 7 Oct 2011 at 4:28
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.