Coder Social home page Coder Social logo

tylere / pykml Goto Github PK

View Code? Open in Web Editor NEW
12.0 4.0 9.0 413 KB

pyKML is a Python package for creating, parsing, manipulating, and validating KML documents.

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%
kml google-earth python3 geospatial

pykml's Introduction

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)

pykml's People

Contributors

sergebdt avatar tylere avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pykml's Issues

Interfacing with python geo libraries

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 example: realtime updates from a latitude feed

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 example of visualizing global carbon emissions time series

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

Error localization when kml does not match kml.

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 function for creating overlays of text

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 example: placing GeoTiffs

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

Balloon helper - charting

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

Any missing contributions from Google?

There haven't been any changes to the pyKML inside of Google since Sept 2020. However, in case something was not contributed upstream that should be, here is a snapshot. I think the only thing that is not already here are the tests in simple_test.py. There were some XSD schema changes that are not useful to the general community.
pykml-as-in-google.zip

Avoid using setuptools

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

Improve the ability to output CDATA wrapped strings

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

[security] Potential for XXE-type exploits when parsing untrusted documents

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:

is there a mac OSX version of pykml?

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

Calculate intermediate camera parameters using splines

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

No module named kml_gx

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

Allow validation against a schema on a remote URL

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

Parsing without schema validatation doesn't preserve CDATA sections

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.