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
90707b32
Commit
90707b32
authored
Sep 09, 2014
by
Ian Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test coverage for Overlay class
parent
e1e174cf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
10 deletions
+87
-10
fastkml/kml.py
fastkml/kml.py
+32
-10
fastkml/test_main.py
fastkml/test_main.py
+55
-0
No files found.
fastkml/kml.py
View file @
90707b32
...
...
@@ -28,6 +28,7 @@ http://schemas.opengis.net/kml/.
try
:
import
urlparse
except
ImportError
:
# Python 3
import
urllib.parse
as
urlparse
import
warnings
...
...
@@ -650,19 +651,15 @@ class _Overlay(_Feature):
Base type for image overlays drawn on the planet surface or on the screen
A Container element holds one or more Features and allows the
creation of nested hierarchies.
subclasses are:
* GroundOverlay
* PhotoOverlay
* ScreenOverlay
A Container element holds one or more Features and allows the creation of
nested hierarchies.
"""
_color
=
None
# Color values expressed in hexadecimal notation, including opacity (alpha)
# values. The order of expression is alp
ha, blue, green, red (AABBGGRR).
#
The range of values for any one color is 0 to 255 (00 to ff). For
# opacity, 00 is fully transparent and ff is fully opaque.
# values. The order of expression is alp
Overlayha, blue, green, red
#
(AABBGGRR). The range of values for any one color is 0 to 255 (00 to ff).
#
For
opacity, 00 is fully transparent and ff is fully opaque.
_drawOrder
=
None
# Defines the stacking order for the images in overlapping overlays.
...
...
@@ -703,7 +700,7 @@ class _Overlay(_Feature):
except
(
ValueError
,
TypeError
):
self
.
_drawOrder
=
None
else
:
self
.
_drawOrder
=
value
self
.
_drawOrder
=
str
(
value
)
@
property
def
icon
(
self
):
...
...
@@ -722,6 +719,31 @@ class _Overlay(_Feature):
else
:
raise
ValueError
def
etree_element
(
self
):
element
=
super
(
_Overlay
,
self
).
etree_element
()
if
self
.
_color
:
color
=
etree
.
SubElement
(
element
,
"%scolor"
%
self
.
ns
)
color
.
text
=
self
.
_color
if
self
.
_drawOrder
:
drawOrder
=
etree
.
SubElement
(
element
,
"%sdrawOrder"
%
self
.
ns
)
drawOrder
.
text
=
self
.
_drawOrder
if
self
.
_icon
:
icon
=
etree
.
SubElement
(
element
,
"%sicon"
%
self
.
ns
)
icon
.
text
=
self
.
_icon
return
element
class
GroundOverlay
(
_Overlay
):
"""
This element draws an image overlay draped onto the terrain. The <href>
child of <Icon> specifies the image to be used as the overlay. This file
can be either on a local file system or on a web server. If this element is
omitted or contains no <href>, a rectangle is drawn using the color and
LatLonBox bounds defined by the ground overlay.
"""
__name__
=
'GroundOverlay'
class
Document
(
_Container
):
"""
...
...
fastkml/test_main.py
View file @
90707b32
...
...
@@ -22,6 +22,7 @@ from fastkml import styles
from
fastkml
import
base
from
fastkml
import
atom
from
fastkml
import
config
from
fastkml
import
gx
import
datetime
from
dateutil.tz
import
tzutc
,
tzoffset
...
...
@@ -115,6 +116,17 @@ class BaseClassesTestCase(unittest.TestCase):
self
.
assertEqual
(
o
.
_color
,
None
)
self
.
assertEqual
(
o
.
_drawOrder
,
None
)
self
.
assertEqual
(
o
.
_icon
,
None
)
self
.
assertRaises
(
NotImplementedError
,
o
.
etree_element
)
def
test_atom_link
(
self
):
ns
=
'{http://www.opengis.net/kml/2.2}'
l
=
atom
.
Link
(
ns
=
ns
)
self
.
assertEqual
(
l
.
ns
,
ns
)
def
test_atom_person
(
self
):
ns
=
'{http://www.opengis.net/kml/2.2}'
p
=
atom
.
_Person
(
ns
=
ns
)
self
.
assertEqual
(
p
.
ns
,
ns
)
class
BuildKmlTestCase
(
unittest
.
TestCase
):
...
...
@@ -1939,6 +1951,21 @@ class Force3DTestCase(unittest.TestCase):
class
BaseOverlayTestCase
(
unittest
.
TestCase
):
def
test_color
(
self
):
o
=
kml
.
_Overlay
(
name
=
'An Overlay'
)
o
.
color
=
'00010203'
self
.
assertEqual
(
o
.
color
,
'00010203'
)
def
test_draw_order_string
(
self
):
o
=
kml
.
_Overlay
(
name
=
'An Overlay'
)
o
.
drawOrder
=
'1'
self
.
assertEqual
(
o
.
drawOrder
,
'1'
)
def
test_draw_order_int
(
self
):
o
=
kml
.
_Overlay
(
name
=
'An Overlay'
)
o
.
drawOrder
=
1
self
.
assertEqual
(
o
.
drawOrder
,
'1'
)
def
test_icon_without_tag
(
self
):
o
=
kml
.
_Overlay
(
name
=
'An Overlay'
)
o
.
icon
=
'http://example.com/'
...
...
@@ -1972,6 +1999,34 @@ class BaseOverlayTestCase(unittest.TestCase):
o
.
icon
=
12345
class
GroundOverlayTestCase
(
unittest
.
TestCase
):
def
test_default_to_string
(
self
):
g
=
kml
.
GroundOverlay
()
expected
=
(
'<kml:GroundOverlay xmlns:kml="http://www.opengis.net/kml/2.2">'
'<kml:visibility>1</kml:visibility>'
'</kml:GroundOverlay>'
)
self
.
assertEqual
(
g
.
to_string
(
prettyprint
=
False
),
expected
)
def
test_to_string
(
self
):
g
=
kml
.
GroundOverlay
()
g
.
icon
=
'http://example.com'
g
.
drawOrder
=
1
g
.
color
=
'00010203'
expected
=
(
'<kml:GroundOverlay xmlns:kml="http://www.opengis.net/kml/2.2">'
'<kml:visibility>1</kml:visibility>'
'<kml:color>00010203</kml:color>'
'<kml:drawOrder>1</kml:drawOrder>'
'<kml:icon><href>http://example.com</href></kml:icon>'
'</kml:GroundOverlay>'
)
self
.
assertEqual
(
g
.
to_string
(
prettyprint
=
False
),
expected
)
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
BaseClassesTestCase
))
...
...
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