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
a0cdbb8d
Commit
a0cdbb8d
authored
Dec 20, 2012
by
Christian Ledermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add get_style_by_url to document
parent
95a282da
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
0 deletions
+50
-0
fastkml/kml.py
fastkml/kml.py
+8
-0
fastkml/test_main.py
fastkml/test_main.py
+42
-0
No files found.
fastkml/kml.py
View file @
a0cdbb8d
...
...
@@ -26,6 +26,8 @@ http://schemas.opengis.net/kml/.
"""
import
urlparse
from
.geometry
import
Point
,
LineString
,
Polygon
from
.geometry
import
MultiPoint
,
MultiLineString
,
MultiPolygon
from
.geometry
import
LinearRing
...
...
@@ -534,6 +536,12 @@ class Document(_Container):
feature
.
from_element
(
placemark
)
self
.
append
(
feature
)
def
get_style_by_url
(
self
,
styleUrl
):
id
=
urlparse
.
urlparse
(
styleUrl
).
fragment
for
style
in
self
.
styles
():
if
style
.
id
==
id
:
return
style
class
Folder
(
_Container
):
"""
...
...
fastkml/test_main.py
View file @
a0cdbb8d
...
...
@@ -771,6 +771,48 @@ class StyleFromStringTestCase( unittest.TestCase ):
k2
.
from_string
(
k
.
to_string
())
self
.
assertEqual
(
k
.
to_string
(),
k2
.
to_string
())
def
test_get_style_by_url
(
self
):
doc
=
"""<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Document.kml</name>
<open>1</open>
<Style id="exampleStyleDocument">
<LabelStyle>
<color>ff0000cc</color>
</LabelStyle>
</Style>
<StyleMap id="styleMapExample">
<Pair>
<key>normal</key>
<styleUrl>#normalState</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#highlightState</styleUrl>
</Pair>
</StyleMap>
<Style id="linestyleExample">
<LineStyle>
<color>7f0000ff</color>
<width>4</width>
</LineStyle>
</Style>
</Document>
</kml>"""
k
=
kml
.
KML
()
k
.
from_string
(
doc
)
self
.
assertEqual
(
len
(
list
(
k
.
features
())),
1
)
document
=
list
(
k
.
features
())[
0
]
style
=
document
.
get_style_by_url
(
'http://localhost:8080/somepath#exampleStyleDocument'
)
self
.
assertTrue
(
isinstance
(
list
(
style
.
styles
())[
0
],
styles
.
LabelStyle
))
style
=
document
.
get_style_by_url
(
'somepath#linestyleExample'
)
self
.
assertTrue
(
isinstance
(
list
(
style
.
styles
())[
0
],
styles
.
LineStyle
))
style
=
document
.
get_style_by_url
(
'#styleMapExample'
)
self
.
assertTrue
(
isinstance
(
style
,
styles
.
StyleMap
))
class
DateTimeTestCase
(
unittest
.
TestCase
):
def
test_timestamp
(
self
):
...
...
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