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
562c8677
Commit
562c8677
authored
Jun 26, 2012
by
Christian Ledermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add styelUrl to features, add from_element to stylemap, from_element, test for stylemap
parent
3caf41f6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
129 additions
and
4 deletions
+129
-4
fastkml/atom.py
fastkml/atom.py
+2
-0
fastkml/kml.py
fastkml/kml.py
+6
-1
fastkml/styles.py
fastkml/styles.py
+35
-1
fastkml/tests.py
fastkml/tests.py
+84
-0
setup.py
setup.py
+2
-2
No files found.
fastkml/atom.py
View file @
562c8677
...
...
@@ -13,6 +13,8 @@ href attribute - URL of the web page containing the KML/KMZ file
These elements are defined in the Atom Syndication Format. The complete
specification is found at http://atompub.org.
This library only implements a subset of Atom that is useful with KML
"""
import
logging
logger
=
logging
.
getLogger
(
'fastkml.atom'
)
...
...
fastkml/kml.py
View file @
562c8677
...
...
@@ -214,6 +214,11 @@ class _Feature(object):
s
=
StyleMap
(
self
.
ns
)
s
.
from_element
(
style
)
self
.
append_style
(
s
)
style_url
=
element
.
find
(
'%sstyleUrl'
%
self
.
ns
)
if
style_url
:
s
=
StyleUrl
(
self
.
ns
)
s
.
from_element
(
style_url
)
self
.
styleUrl
=
s
.
url
...
...
@@ -470,7 +475,7 @@ class Placemark(_Feature):
if
self
.
geometry
is
not
None
:
element
.
append
(
self
.
_etree_geometry
())
else
:
logger
.
warn
(
'Object does not have a geometry'
)
logger
.
error
(
'Object does not have a geometry'
)
return
element
...
...
fastkml/styles.py
View file @
562c8677
...
...
@@ -164,8 +164,42 @@ class StyleMap(_StyleSelector):
super
(
StyleMap
,
self
).
__init__
(
ns
,
id
)
pass
def
from_element
(
self
,
element
):
super
(
StyleMap
,
self
).
from_element
(
element
)
pairs
=
element
.
findall
(
'%sPair'
%
self
.
ns
)
for
pair
in
pairs
:
key
=
pair
.
find
(
'%skey'
%
self
.
ns
)
style
=
pair
.
find
(
'%sStyle'
%
self
.
ns
)
style_url
=
pair
.
find
(
'%sstyleUrl'
%
self
.
ns
)
if
key
.
text
==
"highlight"
:
if
style
is
not
None
:
highlight
=
Style
(
self
.
ns
)
highlight
.
from_element
(
style
)
elif
style_url
is
not
None
:
highlight
=
StyleUrl
(
self
.
ns
)
highlight
.
from_element
(
style_url
)
else
:
raise
ValueError
self
.
highlight
=
highlight
elif
key
.
text
==
"normal"
:
if
style
is
not
None
:
normal
=
Style
(
self
.
ns
)
normal
.
from_element
(
style
)
elif
style_url
is
not
None
:
normal
=
StyleUrl
(
self
.
ns
)
normal
.
from_element
(
style_url
)
else
:
import
ipdb
;
ipdb
.
set_trace
()
raise
ValueError
self
.
normal
=
normal
else
:
raise
ValueError
def
etree_element
(
self
):
element
=
super
(
Style
,
self
).
etree_element
()
element
=
super
(
Style
Map
,
self
).
etree_element
()
if
self
.
normal
:
if
isinstance
(
self
.
normal
,
(
Style
,
StyleUrl
)):
pair
=
etree
.
SubElement
(
element
,
"%sPair"
%
self
.
ns
)
...
...
fastkml/tests.py
View file @
562c8677
...
...
@@ -8,6 +8,7 @@ from shapely.geometry import Point, LineString, Polygon
from
shapely.geometry
import
MultiPoint
,
MultiLineString
,
MultiPolygon
from
shapely.geometry.polygon
import
LinearRing
class
BuildKmlTestCase
(
unittest
.
TestCase
):
""" Build a simple KML File """
def
test_kml
(
self
):
...
...
@@ -331,6 +332,7 @@ class StyleFromStringTestCase( unittest.TestCase ):
k2
=
kml
.
KML
()
k2
.
from_string
(
k
.
to_string
())
self
.
assertEqual
(
k
.
to_string
(),
k2
.
to_string
())
print
k
.
to_string
()
def
test_iconstyle
(
self
):
doc
=
"""<?xml version="1.0" encoding="UTF-8"?>
...
...
@@ -362,6 +364,7 @@ class StyleFromStringTestCase( unittest.TestCase ):
k2
=
kml
.
KML
()
k2
.
from_string
(
k
.
to_string
())
self
.
assertEqual
(
k
.
to_string
(),
k2
.
to_string
())
print
k
.
to_string
()
def
test_linestyle
(
self
):
doc
=
"""<?xml version="1.0" encoding="UTF-8"?>
...
...
@@ -389,6 +392,7 @@ class StyleFromStringTestCase( unittest.TestCase ):
k2
=
kml
.
KML
()
k2
.
from_string
(
k
.
to_string
())
self
.
assertEqual
(
k
.
to_string
(),
k2
.
to_string
())
print
k
.
to_string
()
def
test_polystyle
(
self
):
doc
=
"""<?xml version="1.0" encoding="UTF-8"?>
...
...
@@ -416,6 +420,7 @@ class StyleFromStringTestCase( unittest.TestCase ):
k2
=
kml
.
KML
()
k2
.
from_string
(
k
.
to_string
())
self
.
assertEqual
(
k
.
to_string
(),
k2
.
to_string
())
print
k
.
to_string
()
def
test_styles
(
self
):
doc
=
"""<?xml version="1.0" encoding="UTF-8"?>
...
...
@@ -456,6 +461,84 @@ class StyleFromStringTestCase( unittest.TestCase ):
k2
=
kml
.
KML
()
k2
.
from_string
(
k
.
to_string
())
self
.
assertEqual
(
k
.
to_string
(),
k2
.
to_string
())
print
k
.
to_string
()
def
test_stylemapurl
(
self
):
doc
=
"""<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<StyleMap id="styleMapExample">
<Pair>
<key>normal</key>
<styleUrl>#normalState</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#highlightState</styleUrl>
</Pair>
</StyleMap>
</Document>
</kml>"""
k
=
kml
.
KML
()
k
.
from_string
(
doc
)
self
.
assertEqual
(
len
(
k
.
features
()),
1
)
self
.
assertTrue
(
isinstance
(
list
(
k
.
features
()[
0
].
styles
())[
0
],
styles
.
StyleMap
))
sm
=
list
(
list
(
k
.
features
()[
0
].
styles
()))[
0
]
self
.
assertTrue
(
isinstance
(
sm
.
normal
,
styles
.
StyleUrl
))
self
.
assertEqual
(
sm
.
normal
.
url
,
'#normalState'
)
self
.
assertTrue
(
isinstance
(
sm
.
highlight
,
styles
.
StyleUrl
))
self
.
assertEqual
(
sm
.
highlight
.
url
,
'#highlightState'
)
k2
=
kml
.
KML
()
k2
.
from_string
(
k
.
to_string
())
self
.
assertEqual
(
k
.
to_string
(),
k2
.
to_string
())
def
test_stylemapstyles
(
self
):
doc
=
"""<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<StyleMap id="styleMapExample">
<Pair>
<key>normal</key>
<Style id="exampleStyleDocument">
<LabelStyle>
<color>ff0000cc</color>
</LabelStyle>
</Style>
</Pair>
<Pair>
<key>highlight</key>
<Style id="examplePolyStyle">
<PolyStyle>
<color>ff0000cc</color>
<colorMode>random</colorMode>
</PolyStyle>
<LineStyle>
<color>ff0000ff</color>
<width>15</width>
</LineStyle>
</Style>
</Pair>
</StyleMap>
</Document>
</kml>"""
k
=
kml
.
KML
()
k
.
from_string
(
doc
)
self
.
assertEqual
(
len
(
k
.
features
()),
1
)
self
.
assertTrue
(
isinstance
(
list
(
k
.
features
()[
0
].
styles
())[
0
],
styles
.
StyleMap
))
sm
=
list
(
list
(
k
.
features
()[
0
].
styles
()))[
0
]
self
.
assertTrue
(
isinstance
(
sm
.
normal
,
styles
.
Style
))
self
.
assertEqual
(
len
(
list
(
sm
.
normal
.
styles
())),
1
)
self
.
assertTrue
(
isinstance
(
list
(
sm
.
normal
.
styles
())[
0
],
styles
.
LabelStyle
))
self
.
assertTrue
(
isinstance
(
sm
.
highlight
,
styles
.
Style
))
self
.
assertTrue
(
isinstance
(
sm
.
highlight
,
styles
.
Style
))
self
.
assertEqual
(
len
(
list
(
sm
.
highlight
.
styles
())),
2
)
self
.
assertTrue
(
isinstance
(
list
(
sm
.
highlight
.
styles
())[
0
],
styles
.
LineStyle
))
self
.
assertTrue
(
isinstance
(
list
(
sm
.
highlight
.
styles
())[
1
],
styles
.
PolyStyle
))
k2
=
kml
.
KML
()
k2
.
from_string
(
k
.
to_string
())
self
.
assertEqual
(
k
.
to_string
(),
k2
.
to_string
())
def
test_suite
():
suite
=
unittest
.
TestSuite
()
...
...
@@ -466,3 +549,4 @@ def test_suite():
if
__name__
==
'__main__'
:
unittest
.
main
()
setup.py
View file @
562c8677
from
setuptools
import
setup
,
find_packages
import
sys
,
os
version
=
'0.
0
'
version
=
'0.
1
'
setup
(
name
=
'fastkml'
,
version
=
version
,
...
...
@@ -14,7 +14,7 @@ setup(name='fastkml',
"Programming Language :: Python"
,
'Intended Audience :: Developers'
,
'License :: OSI Approved :: GNU General Public License (GPL)'
,
'Development Status ::
4 - Bet
a'
,
'Development Status ::
3 - Alph
a'
,
'Operating System :: OS Independent'
,
],
# Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
keywords
=
'GIS KML Google Maps OpenLayers'
,
...
...
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