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
e3191e04
Commit
e3191e04
authored
Nov 26, 2013
by
Christian Ledermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make snippet a first class citizen, set kml as default namespace
parent
d0cd8a22
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
14 deletions
+46
-14
fastkml/__init__.py
fastkml/__init__.py
+1
-0
fastkml/kml.py
fastkml/kml.py
+43
-12
fastkml/test_main.py
fastkml/test_main.py
+2
-2
No files found.
fastkml/__init__.py
View file @
e3191e04
...
...
@@ -17,6 +17,7 @@
from
.kml
import
KML
,
Document
,
Folder
,
Placemark
from
.kml
import
TimeSpan
,
TimeStamp
from
.kml
import
UntypedExtendedDataElement
,
UntypedExtendedData
from
.styles
import
StyleUrl
,
Style
,
StyleMap
from
.styles
import
IconStyle
,
LineStyle
,
PolyStyle
...
...
fastkml/kml.py
View file @
e3191e04
...
...
@@ -110,14 +110,14 @@ class KML(object):
raise
TypeError
def
etree_element
(
self
):
root
=
etree
.
Element
(
'%skml'
%
self
.
ns
)
# self.ns may be empty, which leads to unprefixed kml elements.
# However, in this case the xlmns should still be mentioned on the kml
# element, just without prefix.
if
not
self
.
ns
:
root
=
etree
.
Element
(
'%skml'
%
self
.
ns
)
root
.
set
(
'xmlns'
,
config
.
NS
[
1
:
-
1
])
else
:
root
=
etree
.
Element
(
'%skml'
%
self
.
ns
,
nsmap
=
{
None
:
self
.
ns
[
1
:
-
1
]})
for
feature
in
self
.
features
():
root
.
append
(
feature
.
etree_element
())
return
root
...
...
@@ -386,6 +386,36 @@ class _Feature(_BaseObject):
yield
style
else
:
raise
TypeError
@
property
def
snippet
(
self
):
if
self
.
_snippet
:
if
isinstance
(
self
.
_snippet
,
dict
):
text
=
self
.
_snippet
.
get
(
'text'
)
if
text
:
assert
(
isinstance
(
text
,
basestring
))
max_lines
=
self
.
_snippet
.
get
(
'maxLines'
,
None
)
if
max_lines
is
None
:
return
{
'text'
:
text
}
elif
int
(
max_lines
)
>
0
:
# if maxLines <=0 ignore it
return
{
'text'
:
text
,
'maxLines'
:
max_lines
}
elif
isinstance
(
self
.
_snippet
,
basestring
):
return
self
.
_snippet
else
:
raise
ValueError
(
"Snippet must be dict of {'text':t, 'maxLines':i} or string"
)
@
snippet
.
setter
def
snippet
(
self
,
snip
=
None
):
self
.
_snippet
=
{}
if
isinstance
(
snip
,
dict
):
self
.
_snippet
[
'text'
]
=
snip
.
get
(
'text'
)
self
.
_snippet
[
'maxLines'
]
=
int
(
snip
.
get
(
'maxLines'
,
0
))
elif
isinstance
(
text
,
basestring
):
self
.
_snippet
[
'text'
]
=
snip
elif
text
is
None
:
self
.
_snippet
=
None
else
:
raise
ValueError
(
"Snippet must be dict of {'text':t, 'maxLines':i} or string"
)
def
etree_element
(
self
):
element
=
super
(
_Feature
,
self
).
etree_element
()
...
...
@@ -404,15 +434,15 @@ class _Feature(_BaseObject):
element
.
append
(
self
.
_styleUrl
.
etree_element
())
for
style
in
self
.
styles
():
element
.
append
(
style
.
etree_element
())
if
self
.
_
snippet
:
if
self
.
snippet
:
snippet
=
etree
.
SubElement
(
element
,
"%sSnippet"
%
self
.
ns
)
if
isinstance
(
self
.
_
snippet
,
basestring
):
snippet
.
text
=
self
.
_
snippet
if
isinstance
(
self
.
snippet
,
basestring
):
snippet
.
text
=
self
.
snippet
else
:
assert
(
isinstance
(
self
.
_
snippet
[
'text'
],
basestring
))
snippet
.
text
=
self
.
_
snippet
[
'text'
]
if
self
.
_
snippet
.
get
(
'maxLines'
):
snippet
.
set
(
'maxLines'
,
str
(
self
.
_
snippet
[
'maxLines'
]))
assert
(
isinstance
(
self
.
snippet
[
'text'
],
basestring
))
snippet
.
text
=
self
.
snippet
[
'text'
]
if
self
.
snippet
.
get
(
'maxLines'
):
snippet
.
set
(
'maxLines'
,
str
(
self
.
snippet
[
'maxLines'
]))
if
(
self
.
_time_span
is
not
None
)
and
(
self
.
_time_stamp
is
not
None
):
raise
ValueError
(
'Either Timestamp or Timespan can be defined, not both'
)
elif
self
.
_time_span
is
not
None
:
...
...
@@ -459,9 +489,10 @@ class _Feature(_BaseObject):
self
.
_styleUrl
=
s
snippet
=
element
.
find
(
'%sSnippet'
%
self
.
ns
)
if
snippet
is
not
None
:
self
.
_snippet
=
{
'text'
:
snippet
.
text
}
_snippet
=
{
'text'
:
snippet
.
text
}
if
snippet
.
get
(
'maxLines'
):
self
.
_snippet
[
'maxLines'
]
=
int
(
snippet
.
get
(
'maxLines'
))
_snippet
[
'maxLines'
]
=
int
(
snippet
.
get
(
'maxLines'
))
self
.
snippet
=
_snippet
timespan
=
element
.
find
(
'%sTimeSpan'
%
self
.
ns
)
if
timespan
is
not
None
:
s
=
TimeSpan
(
self
.
ns
)
...
...
fastkml/test_main.py
View file @
e3191e04
...
...
@@ -120,8 +120,8 @@ class BuildKmlTestCase(unittest.TestCase):
k
=
kml
.
KML
()
self
.
assertEqual
(
len
(
list
(
k
.
features
())),
0
)
if
hasattr
(
etree
,
'register_namespace'
):
self
.
assertEqual
(
str
(
k
.
to_string
())[:
51
],
'<kml
:kml xmlns:kml="http://www.opengis.net/kml/2.2" />'
[:
51
])
self
.
assertEqual
(
str
(
k
.
to_string
())[:
43
],
'<kml
xmlns="http://www.opengis.net/kml/2.2"/>'
[:
43
])
else
:
self
.
assertEqual
(
str
(
k
.
to_string
())[:
51
],
'<ns0:kml xmlns:ns0="http://www.opengis.net/kml/2.2" />'
[:
51
])
...
...
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