Commit e2a563f2 authored by Christian Ledermann's avatar Christian Ledermann

python3 fixes, update documentation

parent 91cce3ce
......@@ -9,26 +9,26 @@ a subset of KML and is aimed at documents that can be read from multiple
clients such as openlayers and google maps rather than to give you all
functionality that KML on google earth provides.
Geometries are handled as pygeoif or shapely (if installed) objects.
Geometries are handled as pygeoif_ or shapely_ (if installed) objects.
.. _pygeoif: http://pypi.python.org/pypi/pygeoif/
.. _shapely: http://pypi.python.org/pypi/Shapely
.. _collective.geo.fastkml: http://pypi.python.org/pypi/collective.geo.fastkml
Limitations
===========
Geometries are limited to the geometry and multigeometry types shapely
provides (Point, LineString, Polygon, MultiPoint, MultiLineString,
MultiPolygon and LinearRing). While KML allows for more abstract
MultiGeometries consisting of a combination of Points, LineStrings
and LinearRings, this is not supported in fastkml.
This is a restriction that I can live with and you will rarely find KML
files that implement more complex geometries.
*Tesselate*, *Extrude* and *Altitude Mode* are assigned to a Geometry or
Geometry collection (MultiGeometry). You cannot assign diffrent
values of *Tesselate*, *Extrude* or *Altitude Mode* on parts of a MultiGeometry.
Usage
=====
You can find more examples in the included tests.py file, here is a
quick overview:
You can find more examples in the included tests.py file or in
collective.geo.fastkml_,
here is a quick overview:
Build a KML from scratch:
......@@ -52,49 +52,49 @@ Example how to build a simple KML file
>>> p.geometry = Polygon([(0, 0, 0), (1, 1, 0), (1, 0, 1)])
>>> f2.append(p)
>>> print k.to_string(prettyprint=True)
'<ns0:kml xmlns:ns0="http://www.opengis.net/kml/2.2">
<ns0:Document id="docid">
<ns0:name>doc name</ns0:name>
<ns0:description>doc description</ns0:description>
<ns0:visibility>1</ns0:visibility>
<ns0:open>0</ns0:open>
<ns0:Folder id="fid">
<ns0:name>f name</ns0:name>
<ns0:description>f description</ns0:description>
<ns0:visibility>1</ns0:visibility>
<ns0:open>0</ns0:open>
<ns0:Folder id="nested-fid">
<ns0:name>nested f name</ns0:name>
<ns0:description>nested f description</ns0:description>
<ns0:visibility>1</ns0:visibility>
<ns0:open>0</ns0:open>
</ns0:Folder>
</ns0:Folder>
<ns0:Folder id="id2">
<ns0:name>name2</ns0:name>
<ns0:description>description2</ns0:description>
<ns0:visibility>1</ns0:visibility>
<ns0:open>0</ns0:open>
<ns0:Placemark id="id">
<ns0:name>name</ns0:name>
<ns0:description>description</ns0:description>
<ns0:visibility>1</ns0:visibility>
<ns0:open>0</ns0:open>
<ns0:Polygon>
<ns0:outerBoundaryIs>
<ns0:LinearRing>
<ns0:coordinates>0.000000,0.000000,0.000000
'<kml:kml xmlns:ns0="http://www.opengis.net/kml/2.2">
<kml:Document id="docid">
<kml:name>doc name</kml:name>
<kml:description>doc description</kml:description>
<kml:visibility>1</kml:visibility>
<kml:open>0</kml:open>
<kml:Folder id="fid">
<kml:name>f name</kml:name>
<kml:description>f description</kml:description>
<kml:visibility>1</kml:visibility>
<kml:open>0</kml:open>
<kml:Folder id="nested-fid">
<kml:name>nested f name</kml:name>
<kml:description>nested f description</kml:description>
<kml:visibility>1</kml:visibility>
<kml:open>0</kml:open>
</kml:Folder>
</kml:Folder>
<kml:Folder id="id2">
<kml:name>name2</kml:name>
<kml:description>description2</kml:description>
<kml:visibility>1</kml:visibility>
<kml:open>0</kml:open>
<kml:Placemark id="id">
<kml:name>name</kml:name>
<kml:description>description</kml:description>
<kml:visibility>1</kml:visibility>
<kml:open>0</kml:open>
<kml:Polygon>
<kml:outerBoundaryIs>
<kml:LinearRing>
<kml:coordinates>0.000000,0.000000,0.000000
1.000000,1.000000,0.000000
1.000000,0.000000,1.000000
0.000000,0.000000,0.000000
</ns0:coordinates>
</ns0:LinearRing>
</ns0:outerBoundaryIs>
</ns0:Polygon>
</ns0:Placemark>
</ns0:Folder>
</ns0:Document>
</ns0:kml>'
</kml:coordinates>
</kml:LinearRing>
</kml:outerBoundaryIs>
</kml:Polygon>
</kml:Placemark>
</kml:Folder>
</kml:Document>
</kml:kml>'
......@@ -143,37 +143,33 @@ You can create a KML object by reading a KML file
'Document Feature 2'
>>> k.features()[0].features()[1].name = "ANOTHER NAME"
>>> print k.to_string(prettyprint=True)
<ns0:kml xmlns:ns0="http://www.opengis.net/kml/2.2">
<ns0:Document>
<ns0:name>Document.kml</ns0:name>
<ns0:visibility>1</ns0:visibility>
<ns0:open>1</ns0:open>
<ns0:Style id="exampleStyleDocument">
<ns0:LabelStyle>
<ns0:color>ff0000cc</ns0:color>
<ns0:scale>1.0</ns0:scale>
</ns0:LabelStyle>
</ns0:Style>
<ns0:Placemark>
<ns0:name>Document Feature 1</ns0:name>
<ns0:visibility>1</ns0:visibility>
<ns0:open>0</ns0:open>
<ns0:Point>
<ns0:coordinates>-122.371000,37.816000,0.000000</ns0:coordinates>
</ns0:Point>
</ns0:Placemark>
<ns0:Placemark>
<ns0:name>ANOTHER NAME</ns0:name>
<ns0:visibility>1</ns0:visibility>
<ns0:open>0</ns0:open>
<ns0:Point>
<ns0:coordinates>-122.370000,37.817000,0.000000</ns0:coordinates>
</ns0:Point>
</ns0:Placemark>
</ns0:Document>
</ns0:kml>
<kml:kml xmlns:ns0="http://www.opengis.net/kml/2.2">
<kml:Document>
<kml:name>Document.kml</kml:name>
<kml:visibility>1</kml:visibility>
<kml:open>1</kml:open>
<kml:Style id="exampleStyleDocument">
<kml:LabelStyle>
<kml:color>ff0000cc</kml:color>
<kml:scale>1.0</kml:scale>
</kml:LabelStyle>
</kml:Style>
<kml:Placemark>
<kml:name>Document Feature 1</kml:name>
<kml:visibility>1</kml:visibility>
<kml:open>0</kml:open>
<kml:Point>
<kml:coordinates>-122.371000,37.816000,0.000000</kml:coordinates>
</kml:Point>
</kml:Placemark>
<kml:Placemark>
<kml:name>ANOTHER NAME</kml:name>
<kml:visibility>1</kml:visibility>
<kml:open>0</kml:open>
<kml:Point>
<kml:coordinates>-122.370000,37.817000,0.000000</kml:coordinates>
</kml:Point>
</kml:Placemark>
</kml:Document>
</kml:kml>
......@@ -5,6 +5,7 @@ Changelog
0.3 (unreleased)
-----------------
- add support for tesselation, altitudeMode and extrude to Geometries
- move implementation of geometry from kml.Placemark to geometry.Geometry
- add support for heterogenous GeometryCollection
- python 3 compatible
......
To Do
======
- Schema and Extended Data
- Balloon Style
- Overlays
......@@ -15,11 +15,11 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
from kml import KML, Document, Folder, Placemark
from kml import TimeSpan, TimeStamp
from .kml import KML, Document, Folder, Placemark
from .kml import TimeSpan, TimeStamp
from styles import StyleUrl, Style, StyleMap
from styles import IconStyle, LineStyle, PolyStyle
from styles import LabelStyle #, BalloonStyle
from .styles import StyleUrl, Style, StyleMap
from .styles import IconStyle, LineStyle, PolyStyle
from .styles import LabelStyle #, BalloonStyle
from atom import Link, Author, Contributor
from .atom import Link, Author, Contributor
......@@ -23,6 +23,13 @@ try:
from shapely.geometry import MultiPoint, MultiLineString, MultiPolygon
from shapely.geometry.polygon import LinearRing
#from shapely.geometry import GeometryCollection
# Sean Gillies:
# I deliberately omitted a geometry collection constructor because
# there was almost no support in GEOS for operations on them. You
# couldn't buffer a collection, for example, or find its difference
# to another geometry. I've seen some signs of this changing in GEOS,
# but until it does I don't think there's any point to the class.
# It wouldn't be much more than a list of geometries.
from pygeoif.geometry import GeometryCollection
from shapely.geometry import asShape
......@@ -119,14 +126,16 @@ class Geometry(_BaseObject):
#'relativeToSeaFloor', 'clampToSeaFloor',
'relativeToGround', 'absolute'])
if self.altitude_mode != 'clampToGround':
element.set('altitudeMode', self.altitude_mode)
am_element = etree.SubElement(element, "%saltitudeMode" %self.ns)
am_element.text = self.altitude_mode
def _set_extrude(self, element):
if self.extrude and self.altitude_mode in ['relativeToGround',
#'relativeToSeaFloor',
'absolute']:
element.set('extrude', '1')
et_element = etree.SubElement(element, "%sextrude" %self.ns)
et_element.text = '1'
def _etree_coordinates(self, coordinates):
clampToGround = (self.altitude_mode == 'clampToGround') or (self.altitude_mode == None)
......@@ -162,7 +171,8 @@ class Geometry(_BaseObject):
self._set_altitude_mode(element)
if self.tessellate and self.altitude_mode in ['clampToGround',
'clampToSeaFloor']:
element.set('tessellate', '1')
ts_element = etree.SubElement(element, "%stessellate" %self.ns)
ts_element.text = '1'
coords = list(linestring.coords)
element.append(self._etree_coordinates(coords))
return element
......
This diff is collapsed.
......@@ -8,7 +8,8 @@ setup(name='fastkml',
description="Fast KML processing in python",
long_description=open(
"README.rst").read() + "\n" +
open(os.path.join("docs", "HISTORY.txt")).read(),
open(os.path.join("docs", "HISTORY.txt")).read() + "\n" +
open(os.path.join("docs", "TODO.txt")).read(),
classifiers=[
"Topic :: Scientific/Engineering :: GIS",
"Programming Language :: Python",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment