How to use fastkml - 10 common examples

To help you get started, we’ve selected a few fastkml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cleder / fastkml / fastkml / test_main.py View on Github external
def test_placemark(self):
        doc = """
          
            Simple placemark
            Attached to the ground. Intelligently places itself
               at the height of the underlying terrain.
            
              -122.0822035425683,37.42228990140251,0
            
          
        """
        k = kml.KML()
        k.from_string(doc)
        self.assertEqual(len(list(k.features())), 1)
        self.assertEqual(list(k.features())[0].name, "Simple placemark")
        k2 = kml.KML()
        k2.from_string(k.to_string())
        self.assertEqual(k.to_string(), k2.to_string())
github cleder / fastkml / fastkml / test_main.py View on Github external
7fffaaff
              1.5
            
            
              ff0000ff
              15
            
            
              7f7faaaa
              random
            
          
          
        
        """
        k = kml.KML()
        k.from_string(doc)
        self.assertEqual(len(list(k.features())), 1)
        self.assertTrue(
            isinstance(list(list(k.features())[0].styles())[0], styles.Style)
        )
        style = list(list(list(k.features())[0].styles())[0].styles())
        self.assertEqual(len(style), 4)
        k2 = kml.KML()
        k2.from_string(k.to_string())
        self.assertEqual(k.to_string(), k2.to_string())
github cleder / fastkml / fastkml / test_main.py View on Github external
<data name="holePar">
                The par for this hole is 
                ]]&gt;
                4
              </data>
              
                Mount Everest
                347.45
                10000
              
            
          
        """
        k = kml.KML()
        k.from_string(doc)

        extended_data = list(k.features())[0].extended_data

        self.assertEqual(extended_data.elements[0].name, 'holeNumber')
        self.assertEqual(extended_data.elements[0].value, '1')
        self.assertTrue(
            '<b>This is hole </b>' in extended_data.elements[0].display_name
        )

        self.assertEqual(extended_data.elements[1].name, 'holePar')
        self.assertEqual(extended_data.elements[1].value, '4')
        self.assertTrue(
            '<i>The par for this hole is </i>' in extended_data.elements[1].display_name
        )
        sd = extended_data.elements[2]
github cleder / fastkml / fastkml / test_main.py View on Github external
def test_BaseObject(self):
        bo = base._BaseObject(id='id0')
        self.assertEqual(bo.id, 'id0')
        self.assertEqual(bo.ns, config.NS)
        self.assertEqual(bo.targetId, None)
        self.assertEqual(bo.__name__, None)
        bo.targetId = 'target'
        self.assertEqual(bo.targetId, 'target')
        bo.ns = ''
        bo.id = None
        self.assertEqual(bo.id, None)
        self.assertEqual(bo.ns, '')
        self.assertRaises(NotImplementedError, bo.etree_element)
        element = etree.Element(config.NS + 'Base')
        self.assertRaises(TypeError, bo.from_element)
        self.assertRaises(TypeError, bo.from_element, element)
        bo.__name__ = 'NotABaseObject'
        self.assertRaises(TypeError, bo.from_element, element)
        # Note that we can coax baseclasses not to throw errors
        bo.__name__ = 'Base'
        bo.ns = config.NS
        bo.from_element(element)
        self.assertEqual(bo.id, None)
        self.assertEqual(bo.ns, config.NS)
        self.assertFalse(bo.etree_element(), None)
        self.assertTrue(len(bo.to_string()) > 1)
github cleder / fastkml / fastkml / test_main.py View on Github external
def testMultiPolygon(self):
        # with holes
        p0 = Polygon(
            [(-1, -1), (2, -1), (2, 2), (-1, -1)],
            [[(0, 0), (1, 0), (1, 1), (0, 0)]]
        )
        # without holes
        p1 = Polygon([(3, 0), (4, 0), (4, 1), (3, 0)])
        g = Geometry(geometry=MultiPolygon([p0, p1]))
        self.assertTrue('MultiGeometry' in str(g.to_string()))
        self.assertTrue('Polygon' in str(g.to_string()))
        self.assertTrue('outerBoundaryIs' in str(g.to_string()))
        self.assertTrue('innerBoundaryIs' in str(g.to_string()))
        self.assertTrue('LinearRing' in str(g.to_string()))
        self.assertTrue(
            'coordinates&gt;0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 0.000000,0.000000-1.000000,-1.000000 2.000000,-1.000000 2.000000,2.000000 -1.000000,-1.0000003.000000,0.000000 4.000000,0.000000 4.000000,1.000000 3.000000,0.000000
github cleder / fastkml / fastkml / test_main.py View on Github external
def testPolygon(self):
        # without holes
        l = Polygon([(0, 0), (1, 0), (1, 1), (0, 0)])
        g = Geometry(geometry=l)
        self.assertEqual(g.geometry, l)
        self.assertTrue('Polygon' in str(g.to_string()))
        self.assertTrue('outerBoundaryIs' in str(g.to_string()))
        self.assertFalse('innerBoundaryIs' in str(g.to_string()))
        self.assertTrue('LinearRing' in str(g.to_string()))
        self.assertTrue(
            'coordinates&gt;0.000000,0.000000 1.000000,0.000000 1.000000,1.000000 0.000000,0.000000
github cleder / fastkml / fastkml / test_main.py View on Github external
def testMultiLineString(self):
        l0 = LineString([(0, 0), (1, 0)])
        l1 = LineString([(0, 1), (1, 1)])
        g = Geometry(geometry=MultiLineString([l0, l1]))
        self.assertTrue('MultiGeometry' in str(g.to_string()))
        self.assertTrue('LineString' in str(g.to_string()))
        self.assertTrue('coordinates&gt;0.000000,0.000000 1.000000,0.0000000.000000,1.000000 1.000000,1.000000
github cleder / fastkml / fastkml / test_main.py View on Github external
def testLineString(self):
        doc = """
            0.000000,0.000000 1.000000,1.000000
        """
        g = Geometry()
        g.from_string(doc)
        self.assertEqual(
            g.geometry.__geo_interface__,
            {'type': 'LineString', 'coordinates': ((0.0, 0.0), (1.0, 1.0))}
        )
github cleder / fastkml / fastkml / test_main.py View on Github external
def test_altitude_mode(self):
        doc = """
          0.000000,1.000000
          clampToGround
        """
        g = Geometry()
        self.assertEqual(g.altitude_mode, None)
        g.from_string(doc)
        self.assertEqual(g.altitude_mode, 'clampToGround')
github cleder / fastkml / fastkml / test_main.py View on Github external
def test_untyped_extended_data_nested(self):
        ns = '{http://www.opengis.net/kml/2.2}'
        k = kml.KML(ns=ns)

        d = kml.Document(ns, 'docid', 'doc name', 'doc description')
        d.extended_data = kml.UntypedExtendedData(elements=[
            kml.UntypedExtendedDataElement(name='type', value='Document')
        ])

        f = kml.Folder(ns, 'fid', 'f name', 'f description')
        f.extended_data = kml.UntypedExtendedData(elements=[
            kml.UntypedExtendedDataElement(name='type', value='Folder')
        ])

        k.append(d)
        d.append(f)

        k2 = kml.KML()
        k2.from_string(k.to_string())

        document_data = list(k2.features())[0].extended_data
        folder_data = list(list(k2.features())[0].features())[0].extended_data