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
af5d252c
Commit
af5d252c
authored
Jul 18, 2012
by
Christian Ledermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
comfortable timespan and timestamp handling for features
parent
7bf44fe5
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
363 additions
and
71 deletions
+363
-71
fastkml/kml.py
fastkml/kml.py
+224
-66
fastkml/styles.py
fastkml/styles.py
+6
-3
fastkml/tests.py
fastkml/tests.py
+133
-2
No files found.
fastkml/kml.py
View file @
af5d252c
This diff is collapsed.
Click to expand it.
fastkml/styles.py
View file @
af5d252c
...
...
@@ -34,8 +34,7 @@ class StyleUrl(_BaseObject):
element
.
text
=
self
.
url
return
element
else
:
logger
.
critical
(
'No url given for styleUrl'
)
raise
ValueError
raise
ValueError
(
'No url given for styleUrl'
)
def
from_element
(
self
,
element
):
super
(
StyleUrl
,
self
).
from_element
(
element
)
...
...
@@ -79,7 +78,7 @@ class Style(_StyleSelector):
def
styles
(
self
):
for
style
in
self
.
_styles
:
if
isinstance
(
style
,
_ColorStyle
):
if
isinstance
(
style
,
(
_ColorStyle
,
BalloonStyle
)
):
yield
style
else
:
raise
TypeError
...
...
@@ -106,6 +105,7 @@ class Style(_StyleSelector):
thestyle
=
LabelStyle
(
self
.
ns
)
thestyle
.
from_element
(
style
)
self
.
append_style
(
thestyle
)
#XXX BalloonStyle
def
etree_element
(
self
):
element
=
super
(
Style
,
self
).
etree_element
()
...
...
@@ -373,4 +373,7 @@ class LabelStyle(_ColorStyle):
self
.
scale
=
float
(
scale
.
text
)
class
BalloonStyle
(
_BaseObject
):
""" Specifies how the description balloon for placemarks is drawn.
The <bgColor>, if specified, is used as the background color of
the balloon."""
pass
fastkml/tests.py
View file @
af5d252c
...
...
@@ -5,6 +5,7 @@ from fastkml import kml
from
fastkml
import
styles
from
fastkml
import
base
from
fastkml
import
config
import
datetime
import
xml.etree.ElementTree
as
etree
from
shapely.geometry
import
Point
,
LineString
,
Polygon
from
shapely.geometry
import
MultiPoint
,
MultiLineString
,
MultiPolygon
...
...
@@ -43,8 +44,28 @@ class BaseClassesTestCase(unittest.TestCase):
def
test_Feature
(
self
):
f
=
kml
.
_Feature
(
name
=
'A Feature'
)
self
.
assertRaises
(
NotImplementedError
,
f
.
etree_element
)
self
.
assertEqual
(
f
.
name
,
'A Feature'
)
self
.
assertEqual
(
f
.
visibility
,
1
)
self
.
assertEqual
(
f
.
isopen
,
0
)
#self.assertEqual(f.atom_author, None)
#self.assertEqual(f.atom_link, None)
#self.assertEqual(f.address, None)
#self.assertEqual(f.phoneNumber, None)
self
.
assertEqual
(
f
.
_snippet
,
None
)
self
.
assertEqual
(
f
.
description
,
None
)
self
.
assertEqual
(
f
.
_styleUrl
,
None
)
self
.
assertEqual
(
f
.
_styles
,
[])
self
.
assertEqual
(
f
.
_time_span
,
None
)
self
.
assertEqual
(
f
.
_time_stamp
,
None
)
#self.assertEqual(f.region, None)
#self.assertEqual(f.extended_data, None)
f
.
__name__
=
'Feature'
f
.
styleUrl
=
'#default'
pass
self
.
assertTrue
(
'Feature>'
in
f
.
to_string
())
self
.
assertTrue
(
'#default'
in
f
.
to_string
())
def
test_Container
(
self
):
pass
...
...
@@ -631,12 +652,122 @@ class StyleFromStringTestCase( unittest.TestCase ):
k2
.
from_string
(
k
.
to_string
())
self
.
assertEqual
(
k
.
to_string
(),
k2
.
to_string
())
class
DateTimeTestCase
(
unittest
.
TestCase
):
def
test_timestamp
(
self
):
now
=
datetime
.
datetime
.
now
()
ts
=
kml
.
TimeStamp
(
timestamp
=
now
)
self
.
assertEqual
(
ts
.
timestamp
,
[
now
,
'dateTime'
])
self
.
assertTrue
(
'TimeStamp>'
in
ts
.
to_string
())
self
.
assertTrue
(
'when>'
in
ts
.
to_string
())
self
.
assertTrue
(
now
.
isoformat
()
in
ts
.
to_string
())
y2k
=
datetime
.
date
(
2000
,
1
,
1
)
ts
=
kml
.
TimeStamp
(
timestamp
=
y2k
)
self
.
assertEqual
(
ts
.
timestamp
,
[
y2k
,
'date'
])
self
.
assertTrue
(
'2000-01-01'
in
ts
.
to_string
())
def
test_timestamp_resolution
(
self
):
now
=
datetime
.
datetime
.
now
()
ts
=
kml
.
TimeStamp
(
timestamp
=
now
)
self
.
assertTrue
(
now
.
isoformat
()
in
ts
.
to_string
())
ts
.
timestamp
[
1
]
=
'date'
self
.
assertTrue
(
now
.
date
().
isoformat
()
in
ts
.
to_string
())
self
.
assertFalse
(
now
.
isoformat
()
in
ts
.
to_string
())
year
=
str
(
now
.
year
)
ym
=
now
.
strftime
(
'%Y-%m'
)
ts
.
timestamp
[
1
]
=
'gYearMonth'
self
.
assertTrue
(
ym
in
ts
.
to_string
())
self
.
assertFalse
(
now
.
date
().
isoformat
()
in
ts
.
to_string
())
ts
.
timestamp
[
1
]
=
'gYear'
self
.
assertTrue
(
year
in
ts
.
to_string
())
self
.
assertFalse
(
ym
in
ts
.
to_string
())
ts
.
timestamp
=
None
self
.
assertRaises
(
TypeError
,
ts
.
to_string
)
def
test_timespan
(
self
):
now
=
datetime
.
datetime
.
now
()
y2k
=
datetime
.
datetime
(
2000
,
1
,
1
)
ts
=
kml
.
TimeSpan
(
end
=
now
,
begin
=
y2k
)
self
.
assertEqual
(
ts
.
end
,
[
now
,
'dateTime'
])
self
.
assertEqual
(
ts
.
begin
,
[
y2k
,
'dateTime'
])
self
.
assertTrue
(
'TimeSpan>'
in
ts
.
to_string
())
self
.
assertTrue
(
'begin>'
in
ts
.
to_string
())
self
.
assertTrue
(
'end>'
in
ts
.
to_string
())
self
.
assertTrue
(
now
.
isoformat
()
in
ts
.
to_string
())
self
.
assertTrue
(
y2k
.
isoformat
()
in
ts
.
to_string
())
ts
.
end
=
None
self
.
assertFalse
(
now
.
isoformat
()
in
ts
.
to_string
())
self
.
assertTrue
(
y2k
.
isoformat
()
in
ts
.
to_string
())
ts
.
begin
=
None
self
.
assertRaises
(
ValueError
,
ts
.
to_string
)
def
test_feature_timestamp
(
self
):
now
=
datetime
.
datetime
.
now
()
f
=
kml
.
Document
()
f
.
timeStamp
=
now
self
.
assertTrue
(
now
.
isoformat
()
in
f
.
to_string
())
self
.
assertTrue
(
'TimeStamp>'
in
f
.
to_string
())
self
.
assertTrue
(
'when>'
in
f
.
to_string
())
f
.
timeStamp
=
now
.
date
()
self
.
assertTrue
(
now
.
date
().
isoformat
()
in
f
.
to_string
())
self
.
assertFalse
(
now
.
isoformat
()
in
f
.
to_string
())
f
.
timeStamp
=
None
self
.
assertFalse
(
'TimeStamp>'
in
f
.
to_string
())
def
test_feature_timespan
(
self
):
now
=
datetime
.
datetime
.
now
()
y2k
=
datetime
.
date
(
2000
,
1
,
1
)
f
=
kml
.
Document
()
f
.
begin
=
y2k
f
.
end
=
now
self
.
assertTrue
(
now
.
isoformat
()
in
f
.
to_string
())
self
.
assertTrue
(
'2000-01-01'
in
f
.
to_string
())
self
.
assertTrue
(
'TimeSpan>'
in
f
.
to_string
())
self
.
assertTrue
(
'begin>'
in
f
.
to_string
())
self
.
assertTrue
(
'end>'
in
f
.
to_string
())
f
.
end
=
None
self
.
assertFalse
(
now
.
isoformat
()
in
f
.
to_string
())
self
.
assertTrue
(
'2000-01-01'
in
f
.
to_string
())
self
.
assertTrue
(
'TimeSpan>'
in
f
.
to_string
())
self
.
assertTrue
(
'begin>'
in
f
.
to_string
())
self
.
assertFalse
(
'end>'
in
f
.
to_string
())
f
.
begin
=
None
self
.
assertFalse
(
'TimeSpan>'
in
f
.
to_string
())
def
test_feature_timespan_stamp
(
self
):
now
=
datetime
.
datetime
.
now
()
y2k
=
datetime
.
date
(
2000
,
1
,
1
)
f
=
kml
.
Document
()
f
.
begin
=
y2k
f
.
end
=
now
self
.
assertTrue
(
now
.
isoformat
()
in
f
.
to_string
())
self
.
assertTrue
(
'2000-01-01'
in
f
.
to_string
())
self
.
assertTrue
(
'TimeSpan>'
in
f
.
to_string
())
self
.
assertTrue
(
'begin>'
in
f
.
to_string
())
self
.
assertTrue
(
'end>'
in
f
.
to_string
())
self
.
assertFalse
(
'TimeStamp>'
in
f
.
to_string
())
self
.
assertFalse
(
'when>'
in
f
.
to_string
())
f
.
timeStamp
=
now
self
.
assertTrue
(
now
.
isoformat
()
in
f
.
to_string
())
self
.
assertTrue
(
'TimeStamp>'
in
f
.
to_string
())
self
.
assertTrue
(
'when>'
in
f
.
to_string
())
self
.
assertFalse
(
'2000-01-01'
in
f
.
to_string
())
self
.
assertFalse
(
'TimeSpan>'
in
f
.
to_string
())
self
.
assertFalse
(
'begin>'
in
f
.
to_string
())
self
.
assertFalse
(
'end>'
in
f
.
to_string
())
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
KmlFromStringTestCase
))
suite
.
addTest
(
unittest
.
makeSuite
(
BuildKmlTestCase
))
suite
.
addTest
(
unittest
.
makeSuite
(
StyleFromStringTestCase
))
suite
.
addTest
(
unittest
.
makeSuite
(
BaseClassesTestCase
))
suite
.
addTest
(
unittest
.
makeSuite
(
DateTimeTestCase
))
return
suite
if
__name__
==
'__main__'
:
...
...
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