Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fastkml
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Aurélien Vermylen
fastkml
Commits
e2a563f2
Commit
e2a563f2
authored
Nov 14, 2012
by
Christian Ledermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
python3 fixes, update documentation
parent
91cce3ce
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
172 additions
and
155 deletions
+172
-155
README.rst
README.rst
+80
-84
docs/HISTORY.txt
docs/HISTORY.txt
+1
-0
docs/TODO.txt
docs/TODO.txt
+9
-0
fastkml/__init__.py
fastkml/__init__.py
+6
-6
fastkml/geometry.py
fastkml/geometry.py
+13
-3
fastkml/tests.py
fastkml/tests.py
+61
-61
setup.py
setup.py
+2
-1
No files found.
README.rst
View file @
e2a563f2
...
@@ -9,26 +9,26 @@ a subset of KML and is aimed at documents that can be read from multiple
...
@@ -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
clients such as openlayers and google maps rather than to give you all
functionality that KML on google earth provides.
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
Limitations
===========
===========
Geometries are limited to the geometry and multigeometry types shapely
*Tesselate*, *Extrude* and *Altitude Mode* are assigned to a Geometry or
provides (Point, LineString, Polygon, MultiPoint, MultiLineString,
Geometry collection (MultiGeometry). You cannot assign diffrent
MultiPolygon and LinearRing). While KML allows for more abstract
values of *Tesselate*, *Extrude* or *Altitude Mode* on parts of a MultiGeometry.
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.
Usage
Usage
=====
=====
You can find more examples in the included tests.py file, here is a
You can find more examples in the included tests.py file or in
quick overview:
collective.geo.fastkml_,
here is a quick overview:
Build a KML from scratch:
Build a KML from scratch:
...
@@ -52,49 +52,49 @@ Example how to build a simple KML file
...
@@ -52,49 +52,49 @@ Example how to build a simple KML file
>>> p.geometry = Polygon([(0, 0, 0), (1, 1, 0), (1, 0, 1)])
>>> p.geometry = Polygon([(0, 0, 0), (1, 1, 0), (1, 0, 1)])
>>> f2.append(p)
>>> f2.append(p)
>>> print k.to_string(prettyprint=True)
>>> print k.to_string(prettyprint=True)
'<
ns0
:kml xmlns:ns0="http://www.opengis.net/kml/2.2">
'<
kml
:kml xmlns:ns0="http://www.opengis.net/kml/2.2">
<
ns0
:Document id="docid">
<
kml
:Document id="docid">
<
ns0:name>doc name</ns0
:name>
<
kml:name>doc name</kml
:name>
<
ns0:description>doc description</ns0
:description>
<
kml:description>doc description</kml
:description>
<
ns0:visibility>1</ns0
:visibility>
<
kml:visibility>1</kml
:visibility>
<
ns0:open>0</ns0
:open>
<
kml:open>0</kml
:open>
<
ns0
:Folder id="fid">
<
kml
:Folder id="fid">
<
ns0:name>f name</ns0
:name>
<
kml:name>f name</kml
:name>
<
ns0:description>f description</ns0
:description>
<
kml:description>f description</kml
:description>
<
ns0:visibility>1</ns0
:visibility>
<
kml:visibility>1</kml
:visibility>
<
ns0:open>0</ns0
:open>
<
kml:open>0</kml
:open>
<
ns0
:Folder id="nested-fid">
<
kml
:Folder id="nested-fid">
<
ns0:name>nested f name</ns0
:name>
<
kml:name>nested f name</kml
:name>
<
ns0:description>nested f description</ns0
:description>
<
kml:description>nested f description</kml
:description>
<
ns0:visibility>1</ns0
:visibility>
<
kml:visibility>1</kml
:visibility>
<
ns0:open>0</ns0
:open>
<
kml:open>0</kml
:open>
</
ns0
:Folder>
</
kml
:Folder>
</
ns0
:Folder>
</
kml
:Folder>
<
ns0
:Folder id="id2">
<
kml
:Folder id="id2">
<
ns0:name>name2</ns0
:name>
<
kml:name>name2</kml
:name>
<
ns0:description>description2</ns0
:description>
<
kml:description>description2</kml
:description>
<
ns0:visibility>1</ns0
:visibility>
<
kml:visibility>1</kml
:visibility>
<
ns0:open>0</ns0
:open>
<
kml:open>0</kml
:open>
<
ns0
:Placemark id="id">
<
kml
:Placemark id="id">
<
ns0:name>name</ns0
:name>
<
kml:name>name</kml
:name>
<
ns0:description>description</ns0
:description>
<
kml:description>description</kml
:description>
<
ns0:visibility>1</ns0
:visibility>
<
kml:visibility>1</kml
:visibility>
<
ns0:open>0</ns0
:open>
<
kml:open>0</kml
:open>
<
ns0
:Polygon>
<
kml
:Polygon>
<
ns0
:outerBoundaryIs>
<
kml
:outerBoundaryIs>
<
ns0
:LinearRing>
<
kml
:LinearRing>
<
ns0
:coordinates>0.000000,0.000000,0.000000
<
kml
:coordinates>0.000000,0.000000,0.000000
1.000000,1.000000,0.000000
1.000000,1.000000,0.000000
1.000000,0.000000,1.000000
1.000000,0.000000,1.000000
0.000000,0.000000,0.000000
0.000000,0.000000,0.000000
</
ns0
:coordinates>
</
kml
:coordinates>
</
ns0
:LinearRing>
</
kml
:LinearRing>
</
ns0
:outerBoundaryIs>
</
kml
:outerBoundaryIs>
</
ns0
:Polygon>
</
kml
:Polygon>
</
ns0
:Placemark>
</
kml
:Placemark>
</
ns0
:Folder>
</
kml
:Folder>
</
ns0
:Document>
</
kml
:Document>
</
ns0
:kml>'
</
kml
:kml>'
...
@@ -143,37 +143,33 @@ You can create a KML object by reading a KML file
...
@@ -143,37 +143,33 @@ You can create a KML object by reading a KML file
'Document Feature 2'
'Document Feature 2'
>>> k.features()[0].features()[1].name = "ANOTHER NAME"
>>> k.features()[0].features()[1].name = "ANOTHER NAME"
>>> print k.to_string(prettyprint=True)
>>> print k.to_string(prettyprint=True)
<ns0:kml xmlns:ns0="http://www.opengis.net/kml/2.2">
<kml:kml xmlns:ns0="http://www.opengis.net/kml/2.2">
<ns0:Document>
<kml:Document>
<ns0:name>Document.kml</ns0:name>
<kml:name>Document.kml</kml:name>
<ns0:visibility>1</ns0:visibility>
<kml:visibility>1</kml:visibility>
<ns0:open>1</ns0:open>
<kml:open>1</kml:open>
<ns0:Style id="exampleStyleDocument">
<kml:Style id="exampleStyleDocument">
<ns0:LabelStyle>
<kml:LabelStyle>
<ns0:color>ff0000cc</ns0:color>
<kml:color>ff0000cc</kml:color>
<ns0:scale>1.0</ns0:scale>
<kml:scale>1.0</kml:scale>
</ns0:LabelStyle>
</kml:LabelStyle>
</ns0:Style>
</kml:Style>
<ns0:Placemark>
<kml:Placemark>
<ns0:name>Document Feature 1</ns0:name>
<kml:name>Document Feature 1</kml:name>
<ns0:visibility>1</ns0:visibility>
<kml:visibility>1</kml:visibility>
<ns0:open>0</ns0:open>
<kml:open>0</kml:open>
<ns0:Point>
<kml:Point>
<ns0:coordinates>-122.371000,37.816000,0.000000</ns0:coordinates>
<kml:coordinates>-122.371000,37.816000,0.000000</kml:coordinates>
</ns0:Point>
</kml:Point>
</ns0:Placemark>
</kml:Placemark>
<ns0:Placemark>
<kml:Placemark>
<ns0:name>ANOTHER NAME</ns0:name>
<kml:name>ANOTHER NAME</kml:name>
<ns0:visibility>1</ns0:visibility>
<kml:visibility>1</kml:visibility>
<ns0:open>0</ns0:open>
<kml:open>0</kml:open>
<ns0:Point>
<kml:Point>
<ns0:coordinates>-122.370000,37.817000,0.000000</ns0:coordinates>
<kml:coordinates>-122.370000,37.817000,0.000000</kml:coordinates>
</ns0:Point>
</kml:Point>
</ns0:Placemark>
</kml:Placemark>
</ns0:Document>
</kml:Document>
</ns0:kml>
</kml:kml>
docs/HISTORY.txt
View file @
e2a563f2
...
@@ -5,6 +5,7 @@ Changelog
...
@@ -5,6 +5,7 @@ Changelog
0.3 (unreleased)
0.3 (unreleased)
-----------------
-----------------
- add support for tesselation, altitudeMode and extrude to Geometries
- move implementation of geometry from kml.Placemark to geometry.Geometry
- move implementation of geometry from kml.Placemark to geometry.Geometry
- add support for heterogenous GeometryCollection
- add support for heterogenous GeometryCollection
- python 3 compatible
- python 3 compatible
...
...
docs/TODO.txt
0 → 100644
View file @
e2a563f2
To Do
======
- Schema and Extended Data
- Balloon Style
- Overlays
fastkml/__init__.py
View file @
e2a563f2
...
@@ -15,11 +15,11 @@
...
@@ -15,11 +15,11 @@
# License along with this library; if not, write to the Free Software
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
from
kml
import
KML
,
Document
,
Folder
,
Placemark
from
.
kml
import
KML
,
Document
,
Folder
,
Placemark
from
kml
import
TimeSpan
,
TimeStamp
from
.
kml
import
TimeSpan
,
TimeStamp
from
styles
import
StyleUrl
,
Style
,
StyleMap
from
.
styles
import
StyleUrl
,
Style
,
StyleMap
from
styles
import
IconStyle
,
LineStyle
,
PolyStyle
from
.
styles
import
IconStyle
,
LineStyle
,
PolyStyle
from
styles
import
LabelStyle
#, BalloonStyle
from
.
styles
import
LabelStyle
#, BalloonStyle
from
atom
import
Link
,
Author
,
Contributor
from
.
atom
import
Link
,
Author
,
Contributor
fastkml/geometry.py
View file @
e2a563f2
...
@@ -23,6 +23,13 @@ try:
...
@@ -23,6 +23,13 @@ try:
from
shapely.geometry
import
MultiPoint
,
MultiLineString
,
MultiPolygon
from
shapely.geometry
import
MultiPoint
,
MultiLineString
,
MultiPolygon
from
shapely.geometry.polygon
import
LinearRing
from
shapely.geometry.polygon
import
LinearRing
#from shapely.geometry import GeometryCollection
#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
pygeoif.geometry
import
GeometryCollection
from
shapely.geometry
import
asShape
from
shapely.geometry
import
asShape
...
@@ -119,14 +126,16 @@ class Geometry(_BaseObject):
...
@@ -119,14 +126,16 @@ class Geometry(_BaseObject):
#'relativeToSeaFloor', 'clampToSeaFloor',
#'relativeToSeaFloor', 'clampToSeaFloor',
'relativeToGround'
,
'absolute'
])
'relativeToGround'
,
'absolute'
])
if
self
.
altitude_mode
!=
'clampToGround'
:
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
):
def
_set_extrude
(
self
,
element
):
if
self
.
extrude
and
self
.
altitude_mode
in
[
'relativeToGround'
,
if
self
.
extrude
and
self
.
altitude_mode
in
[
'relativeToGround'
,
#'relativeToSeaFloor',
#'relativeToSeaFloor',
'absolute'
]:
'absolute'
]:
element
.
set
(
'extrude'
,
'1'
)
et_element
=
etree
.
SubElement
(
element
,
"%sextrude"
%
self
.
ns
)
et_element
.
text
=
'1'
def
_etree_coordinates
(
self
,
coordinates
):
def
_etree_coordinates
(
self
,
coordinates
):
clampToGround
=
(
self
.
altitude_mode
==
'clampToGround'
)
or
(
self
.
altitude_mode
==
None
)
clampToGround
=
(
self
.
altitude_mode
==
'clampToGround'
)
or
(
self
.
altitude_mode
==
None
)
...
@@ -162,7 +171,8 @@ class Geometry(_BaseObject):
...
@@ -162,7 +171,8 @@ class Geometry(_BaseObject):
self
.
_set_altitude_mode
(
element
)
self
.
_set_altitude_mode
(
element
)
if
self
.
tessellate
and
self
.
altitude_mode
in
[
'clampToGround'
,
if
self
.
tessellate
and
self
.
altitude_mode
in
[
'clampToGround'
,
'clampToSeaFloor'
]:
'clampToSeaFloor'
]:
element
.
set
(
'tessellate'
,
'1'
)
ts_element
=
etree
.
SubElement
(
element
,
"%stessellate"
%
self
.
ns
)
ts_element
.
text
=
'1'
coords
=
list
(
linestring
.
coords
)
coords
=
list
(
linestring
.
coords
)
element
.
append
(
self
.
_etree_coordinates
(
coords
))
element
.
append
(
self
.
_etree_coordinates
(
coords
))
return
element
return
element
...
...
fastkml/tests.py
View file @
e2a563f2
This diff is collapsed.
Click to expand it.
setup.py
View file @
e2a563f2
...
@@ -8,7 +8,8 @@ setup(name='fastkml',
...
@@ -8,7 +8,8 @@ setup(name='fastkml',
description
=
"Fast KML processing in python"
,
description
=
"Fast KML processing in python"
,
long_description
=
open
(
long_description
=
open
(
"README.rst"
).
read
()
+
"
\
n
"
+
"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
=
[
classifiers
=
[
"Topic :: Scientific/Engineering :: GIS"
,
"Topic :: Scientific/Engineering :: GIS"
,
"Programming Language :: Python"
,
"Programming Language :: Python"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment