Commit d1e738df authored by Ian Lee's avatar Ian Lee

* Added members for Ground Overlay tags.

* Implemented the altitude property and etree_element() functionality.
parent 90707b32
...@@ -743,6 +743,72 @@ class GroundOverlay(_Overlay): ...@@ -743,6 +743,72 @@ class GroundOverlay(_Overlay):
""" """
__name__ = 'GroundOverlay' __name__ = 'GroundOverlay'
_altitude = None
# Specifies the distance above the earth's surface, in meters, and is
# interpreted according to the altitude mode.
_altitudeMode = None
# Specifies how the <altitude> is interpreted. Possible values are:
# clampToGround -
# (default) Indicates to ignore the altitude specification and drape
# the overlay over the terrain.
# absolute -
# Sets the altitude of the overlay relative to sea level, regardless
# of the actual elevation of the terrain beneath the element. For
# example, if you set the altitude of an overlay to 10 meters with an
# absolute altitude mode, the overlay will appear to be at ground
# level if the terrain beneath is also 10 meters above sea level. If
# the terrain is 3 meters above sea level, the overlay will appear
# elevated above the terrain by 7 meters.
# - LatLonBox -
# Specifies where the top, bottom, right, and left sides of a bounding box
# for the ground overlay are aligned. Also, optionally the rotation of the
# overlay.
_north = None
# Specifies the latitude of the north edge of the bounding box, in decimal
# degrees from 0 to ±90.
_south = None
# Specifies the latitude of the south edge of the bounding box, in decimal
# degrees from 0 to ±90.
_east = None
# Specifies the longitude of the east edge of the bounding box, in decimal
# degrees from 0 to ±180. (For overlays that overlap the meridian of 180°
# longitude, values can extend beyond that range.)
_west = None
# Specifies the longitude of the west edge of the bounding box, in decimal
# degrees from 0 to ±180. (For overlays that overlap the meridian of 180°
# longitude, values can extend beyond that range.)
_rotation = None
# Specifies a rotation of the overlay about its center, in degrees. Values
# can be ±180. The default is 0 (north). Rotations are specified in a
# counterclockwise direction.
@property
def altitude(self):
return self._altitude
@altitude.setter
def altitude(self, value):
try:
float(value)
except (ValueError, TypeError):
self._altitude = None
else:
self._altitude = str(value)
def etree_element(self):
element = super(GroundOverlay, self).etree_element()
if self._altitude:
altitude = etree.SubElement(element, "%saltitude" % self.ns)
altitude.text = self._altitude
return element
class Document(_Container): class Document(_Container):
......
...@@ -22,7 +22,7 @@ from fastkml import styles ...@@ -22,7 +22,7 @@ from fastkml import styles
from fastkml import base from fastkml import base
from fastkml import atom from fastkml import atom
from fastkml import config from fastkml import config
from fastkml import gx from fastkml import gx # NOQA
import datetime import datetime
from dateutil.tz import tzutc, tzoffset from dateutil.tz import tzutc, tzoffset
...@@ -93,8 +93,8 @@ class BaseClassesTestCase(unittest.TestCase): ...@@ -93,8 +93,8 @@ class BaseClassesTestCase(unittest.TestCase):
def test_Container(self): def test_Container(self):
f = kml._Container(name='A Container') f = kml._Container(name='A Container')
# apparently you can add documents to containes # apparently you can add documents to containes
#d = kml.Document() # d = kml.Document()
#self.assertRaises(TypeError, f.append, d) # self.assertRaises(TypeError, f.append, d)
p = kml.Placemark() p = kml.Placemark()
f.append(p) f.append(p)
self.assertRaises(NotImplementedError, f.etree_element) self.assertRaises(NotImplementedError, f.etree_element)
...@@ -2026,6 +2026,45 @@ class GroundOverlayTestCase(unittest.TestCase): ...@@ -2026,6 +2026,45 @@ class GroundOverlayTestCase(unittest.TestCase):
self.assertEqual(g.to_string(prettyprint=False), expected) self.assertEqual(g.to_string(prettyprint=False), expected)
def test_altitude_from_int(self):
g = kml.GroundOverlay()
g.altitude = 123
expected = (
'<kml:GroundOverlay xmlns:kml="http://www.opengis.net/kml/2.2">'
'<kml:visibility>1</kml:visibility>'
'<kml:altitude>123</kml:altitude>'
'</kml:GroundOverlay>'
)
self.assertEqual(g.to_string(prettyprint=False), expected)
def test_altitude_from_float(self):
g = kml.GroundOverlay()
g.altitude = 123.4
expected = (
'<kml:GroundOverlay xmlns:kml="http://www.opengis.net/kml/2.2">'
'<kml:visibility>1</kml:visibility>'
'<kml:altitude>123.4</kml:altitude>'
'</kml:GroundOverlay>'
)
self.assertEqual(g.to_string(prettyprint=False), expected)
def test_altitude_from_string(self):
g = kml.GroundOverlay()
g.altitude = '123.4'
expected = (
'<kml:GroundOverlay xmlns:kml="http://www.opengis.net/kml/2.2">'
'<kml:visibility>1</kml:visibility>'
'<kml:altitude>123.4</kml:altitude>'
'</kml:GroundOverlay>'
)
self.assertEqual(g.to_string(prettyprint=False), expected)
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
...@@ -2039,6 +2078,8 @@ def test_suite(): ...@@ -2039,6 +2078,8 @@ def test_suite():
suite.addTest(unittest.makeSuite(SetGeometryTestCase)) suite.addTest(unittest.makeSuite(SetGeometryTestCase))
suite.addTest(unittest.makeSuite(GetGeometryTestCase)) suite.addTest(unittest.makeSuite(GetGeometryTestCase))
suite.addTest(unittest.makeSuite(Force3DTestCase)) suite.addTest(unittest.makeSuite(Force3DTestCase))
suite.addTest(unittest.makeSuite(BaseOverlayTestCase))
suite.addTest(unittest.makeSuite(GroundOverlayTestCase))
return suite return suite
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment