Commit c3096e47 authored by Christian Ledermann's avatar Christian Ledermann

only add z element if it is there or force it using config.FORCE3D

parent 84c56039
......@@ -30,3 +30,5 @@ ATOMNS = '{http://www.w3.org/2005/Atom}'
if hasattr(etree, 'register_namespace'):
etree.register_namespace('kml', NS[1:-1])
etree.register_namespace('atom', ATOMNS[1:-1])
FORCE3D = False
......@@ -644,7 +644,10 @@ class Placemark(_Feature):
def _etree_coordinates(self, coordinates):
element = etree.Element("%scoordinates" %self.ns)
if len(coordinates[0]) == 2:
tuples = ('%f,%f,0.0' % tuple(c) for c in coordinates)
if config.FORCE3D:
tuples = ('%f,%f,0.000000' % tuple(c) for c in coordinates)
else:
tuples = ('%F,%F' % tuple(c) for c in coordinates)
elif len(coordinates[0]) == 3:
tuples = ('%f,%f,%f' % tuple(c) for c in coordinates)
else:
......
......@@ -893,7 +893,18 @@ class AtomTestCase( unittest.TestCase ):
class Force3DTestCase( unittest.TestCase ):
def test3d(self):
ns =''
p2 = kml.Placemark(ns, 'id', 'name', 'description')
p2.geometry = Polygon([(0, 0), (1, 1), (1, 0)])
p3 = kml.Placemark(ns, 'id', 'name', 'description')
p3.geometry = Polygon([(0, 0, 0), (1, 1, 0), (1, 0, 0)])
config.FORCE3D = False
self.assertNotEqual(p2.to_string(), p3.to_string())
config.FORCE3D = True
self.assertEqual(p2.to_string(), p3.to_string())
......@@ -906,6 +917,7 @@ def test_suite():
suite.addTest(unittest.makeSuite(BaseClassesTestCase))
suite.addTest(unittest.makeSuite(DateTimeTestCase))
suite.addTest(unittest.makeSuite(AtomTestCase))
suite.addTest(unittest.makeSuite(Force3DTestCase))
return suite
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