Commit 7b206edb authored by Ian Lee's avatar Ian Lee

Finished implementation of the GroundOverlay class. All that is still needed...

Finished implementation of the GroundOverlay class. All that is still needed is the <gx:latLonQuad> tag.
parent d1e738df
......@@ -697,7 +697,7 @@ class _Overlay(_Feature):
def drawOrder(self, value):
try:
int(value)
except (ValueError, TypeError):
except TypeError:
self._drawOrder = None
else:
self._drawOrder = str(value)
......@@ -747,7 +747,7 @@ class GroundOverlay(_Overlay):
# Specifies the distance above the earth's surface, in meters, and is
# interpreted according to the altitude mode.
_altitudeMode = None
_altitudeMode = 'clampToGround'
# Specifies how the <altitude> is interpreted. Possible values are:
# clampToGround -
# (default) Indicates to ignore the altitude specification and drape
......@@ -789,7 +789,6 @@ class GroundOverlay(_Overlay):
# can be ±180. The default is 0 (north). Rotations are specified in a
# counterclockwise direction.
@property
def altitude(self):
return self._altitude
......@@ -803,11 +802,123 @@ class GroundOverlay(_Overlay):
else:
self._altitude = str(value)
@property
def altitudeMode(self):
return self._altitudeMode
@altitudeMode.setter
def altitudeMode(self, mode):
if mode in ('clampToGround', 'absolute'):
self._altitudeMode = str(mode)
else:
self._altitudeMode = 'clampToGround'
@property
def north(self):
return self._north
@north.setter
def north(self, value):
try:
float(value)
except (ValueError, TypeError):
self._north = None
else:
self._north = str(value)
@property
def south(self):
return self._south
@south.setter
def south(self, value):
try:
float(value)
except (ValueError, TypeError):
self._south = None
else:
self._south = str(value)
@property
def east(self):
return self._east
@east.setter
def east(self, value):
try:
float(value)
except (ValueError, TypeError):
self._east = None
else:
self._east = str(value)
@property
def west(self):
return self._west
@west.setter
def west(self, value):
try:
float(value)
except (ValueError, TypeError):
self._west = None
else:
self._west = str(value)
@property
def rotation(self):
return self._rotation
@rotation.setter
def rotation(self, value):
try:
float(value)
except (ValueError, TypeError):
self._rotation = None
else:
self._rotation = str(value)
def latLonBox(self, north, south, east, west, rotation=0):
# TODO: Check for bounds (0:+/-90 or 0:+/-180 degrees)
try:
float(north)
float(south)
float(east)
float(west)
float(rotation)
except:
raise ValueError
else:
self._north = str(north)
self._south = str(south)
self._east = str(east)
self._west = str(west)
self._rotation = str(rotation)
def etree_element(self):
element = super(GroundOverlay, self).etree_element()
if self._altitude:
altitude = etree.SubElement(element, "%saltitude" % self.ns)
altitude.text = self._altitude
if self._altitudeMode:
altitudeMode = etree.SubElement(
element, "%saltitudeMode" % self.ns
)
altitudeMode.text = self._altitudeMode
if all([self._north, self._south, self._east, self._west]):
latLonBox = etree.SubElement(element, '%slatLonBox' % self.ns)
north = etree.SubElement(latLonBox, '%snorth' % self.ns)
north.text = self._north
south = etree.SubElement(latLonBox, '%ssouth' % self.ns)
south.text = self._south
east = etree.SubElement(latLonBox, '%seast' % self.ns)
east.text = self._east
west = etree.SubElement(latLonBox, '%swest' % self.ns)
west.text = self._west
if self._rotation:
rotation = etree.SubElement(latLonBox, '%srotation' % self.ns)
rotation.text = self._rotation
return element
......
......@@ -1966,6 +1966,11 @@ class BaseOverlayTestCase(unittest.TestCase):
o.drawOrder = 1
self.assertEqual(o.drawOrder, '1')
def test_draw_order_value_error(self):
o = kml._Overlay(name='An Overlay')
o.drawOrder = object()
self.assertEqual(o.drawOrder, None)
def test_icon_without_tag(self):
o = kml._Overlay(name='An Overlay')
o.icon = 'http://example.com/'
......@@ -2000,6 +2005,89 @@ class BaseOverlayTestCase(unittest.TestCase):
class GroundOverlayTestCase(unittest.TestCase):
def setUp(self):
self.g = kml.GroundOverlay()
def test_altitude_int(self):
self.g.altitude = 123
self.assertEqual(self.g.altitude, '123')
def test_altitude_float(self):
self.g.altitude = 123.4
self.assertEqual(self.g.altitude, '123.4')
def test_altitude_string(self):
self.g.altitude = '123'
self.assertEqual(self.g.altitude, '123')
def test_altitude_type_error(self):
self.g.altitude = object()
self.assertEqual(self.g.altitude, None)
def test_altitude_value_error(self):
self.g.altitude = ''
self.assertEqual(self.g.altitude, None)
def test_altitude_mode_default(self):
self.assertEqual(self.g.altitudeMode, 'clampToGround')
def test_altitude_mode_error(self):
self.g.altitudeMode = ''
self.assertEqual(self.g.altitudeMode, 'clampToGround')
def test_altitude_mode_clamp(self):
self.g.altitudeMode = 'clampToGround'
self.assertEqual(self.g.altitudeMode, 'clampToGround')
def test_altitude_mode_absolute(self):
self.g.altitudeMode = 'absolute'
self.assertEqual(self.g.altitudeMode, 'absolute')
def test_latlonbox_function_value_error(self):
with self.assertRaises(ValueError):
self.g.latLonBox('', '', '', '', '')
def test_latlonbox_properties(self):
self.g.north = 10
self.g.south = 20
self.g.east = 30
self.g.west = 40
self.g.rotation = 50
self.assertEqual(self.g.north, '10')
self.assertEqual(self.g.south, '20')
self.assertEqual(self.g.east, '30')
self.assertEqual(self.g.west, '40')
self.assertEqual(self.g.rotation, '50')
def test_latlonbox_properties_type_error(self):
self.g.north = object()
self.g.south = object()
self.g.east = object()
self.g.west = object()
self.g.rotation = object()
self.assertEqual(self.g.north, None)
self.assertEqual(self.g.south, None)
self.assertEqual(self.g.east, None)
self.assertEqual(self.g.west, None)
self.assertEqual(self.g.rotation, None)
def test_latlonbox_properties_value_error(self):
self.g.north = ''
self.g.south = ''
self.g.east = ''
self.g.west = ''
self.g.rotation = ''
self.assertEqual(self.g.north, None)
self.assertEqual(self.g.south, None)
self.assertEqual(self.g.east, None)
self.assertEqual(self.g.west, None)
self.assertEqual(self.g.rotation, None)
class GroundOverlayStringTestCase(unittest.TestCase):
def test_default_to_string(self):
g = kml.GroundOverlay()
expected = (
......@@ -2034,6 +2122,7 @@ class GroundOverlayTestCase(unittest.TestCase):
'<kml:GroundOverlay xmlns:kml="http://www.opengis.net/kml/2.2">'
'<kml:visibility>1</kml:visibility>'
'<kml:altitude>123</kml:altitude>'
'<kml:altitudeMode>clampToGround</kml:altitudeMode>'
'</kml:GroundOverlay>'
)
......@@ -2047,6 +2136,7 @@ class GroundOverlayTestCase(unittest.TestCase):
'<kml:GroundOverlay xmlns:kml="http://www.opengis.net/kml/2.2">'
'<kml:visibility>1</kml:visibility>'
'<kml:altitude>123.4</kml:altitude>'
'<kml:altitudeMode>clampToGround</kml:altitudeMode>'
'</kml:GroundOverlay>'
)
......@@ -2060,6 +2150,113 @@ class GroundOverlayTestCase(unittest.TestCase):
'<kml:GroundOverlay xmlns:kml="http://www.opengis.net/kml/2.2">'
'<kml:visibility>1</kml:visibility>'
'<kml:altitude>123.4</kml:altitude>'
'<kml:altitudeMode>clampToGround</kml:altitudeMode>'
'</kml:GroundOverlay>'
)
self.assertEqual(g.to_string(prettyprint=False), expected)
def test_altitude_mode_absolute(self):
g = kml.GroundOverlay()
g.altitude = '123.4'
g.altitudeMode = 'absolute'
expected = (
'<kml:GroundOverlay xmlns:kml="http://www.opengis.net/kml/2.2">'
'<kml:visibility>1</kml:visibility>'
'<kml:altitude>123.4</kml:altitude>'
'<kml:altitudeMode>absolute</kml:altitudeMode>'
'</kml:GroundOverlay>'
)
self.assertEqual(g.to_string(prettyprint=False), expected)
def test_altitude_mode_unknown_string(self):
g = kml.GroundOverlay()
g.altitude = '123.4'
g.altitudeMode = 'unknown string'
expected = (
'<kml:GroundOverlay xmlns:kml="http://www.opengis.net/kml/2.2">'
'<kml:visibility>1</kml:visibility>'
'<kml:altitude>123.4</kml:altitude>'
'<kml:altitudeMode>clampToGround</kml:altitudeMode>'
'</kml:GroundOverlay>'
)
self.assertEqual(g.to_string(prettyprint=False), expected)
def test_altitude_mode_value(self):
g = kml.GroundOverlay()
g.altitude = '123.4'
g.altitudeMode = 1234
expected = (
'<kml:GroundOverlay xmlns:kml="http://www.opengis.net/kml/2.2">'
'<kml:visibility>1</kml:visibility>'
'<kml:altitude>123.4</kml:altitude>'
'<kml:altitudeMode>clampToGround</kml:altitudeMode>'
'</kml:GroundOverlay>'
)
self.assertEqual(g.to_string(prettyprint=False), expected)
def test_latlonbox_no_rotation(self):
g = kml.GroundOverlay()
g.latLonBox(10, 20, 30, 40)
expected = (
'<kml:GroundOverlay xmlns:kml="http://www.opengis.net/kml/2.2">'
'<kml:visibility>1</kml:visibility>'
'<kml:latLonBox>'
'<kml:north>10</kml:north>'
'<kml:south>20</kml:south>'
'<kml:east>30</kml:east>'
'<kml:west>40</kml:west>'
'<kml:rotation>0</kml:rotation>'
'</kml:latLonBox>'
'</kml:GroundOverlay>'
)
self.assertEqual(g.to_string(prettyprint=False), expected)
def test_latlonbox_rotation(self):
g = kml.GroundOverlay()
g.latLonBox(10, 20, 30, 40, 50)
expected = (
'<kml:GroundOverlay xmlns:kml="http://www.opengis.net/kml/2.2">'
'<kml:visibility>1</kml:visibility>'
'<kml:latLonBox>'
'<kml:north>10</kml:north>'
'<kml:south>20</kml:south>'
'<kml:east>30</kml:east>'
'<kml:west>40</kml:west>'
'<kml:rotation>50</kml:rotation>'
'</kml:latLonBox>'
'</kml:GroundOverlay>'
)
self.assertEqual(g.to_string(prettyprint=False), expected)
def test_latlonbox_nswer(self):
g = kml.GroundOverlay()
g.north = 10
g.south = 20
g.east = 30
g.west = 40
g.rotation = 50
expected = (
'<kml:GroundOverlay xmlns:kml="http://www.opengis.net/kml/2.2">'
'<kml:visibility>1</kml:visibility>'
'<kml:latLonBox>'
'<kml:north>10</kml:north>'
'<kml:south>20</kml:south>'
'<kml:east>30</kml:east>'
'<kml:west>40</kml:west>'
'<kml:rotation>50</kml:rotation>'
'</kml:latLonBox>'
'</kml:GroundOverlay>'
)
......
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