How to use the fastkml.kml.Document function in fastkml

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_feature_timestamp(self):
        now = datetime.datetime.now()
        f = kml.Document()
        f.timeStamp = now
        self.assertEqual(f.timeStamp, now)
        self.assertTrue(now.isoformat() in str(f.to_string()))
        self.assertTrue('TimeStamp>' in str(f.to_string()))
        self.assertTrue('when>' in str(f.to_string()))
        f.timeStamp = now.date()
        self.assertTrue(now.date().isoformat() in str(f.to_string()))
        self.assertFalse(now.isoformat() in str(f.to_string()))
        f.timeStamp = None
        self.assertFalse('TimeStamp>' in str(f.to_string()))
github cleder / fastkml / fastkml / test_main.py View on Github external
def test_styleurl(self):
        f = kml.Document()
        f.styleUrl = '#somestyle'
        self.assertEqual(f.styleUrl, '#somestyle')
        self.assertTrue(isinstance(f._styleUrl, styles.StyleUrl))
        s = styles.StyleUrl(config.NS, url='#otherstyle')
        f.styleUrl = s
        self.assertTrue(isinstance(f._styleUrl, styles.StyleUrl))
        self.assertEqual(f.styleUrl, '#otherstyle')
        f2 = kml.Document()
        f2.from_string(f.to_string())
        self.assertEqual(f.to_string(), f2.to_string())
github cleder / fastkml / fastkml / test_main.py View on Github external
def test_author(self):
        d = kml.Document()
        d.author = 'Christian Ledermann'
        self.assertTrue('Christian Ledermann' in str(d.to_string()))
        a = atom.Author(name='Nobody', uri='http://localhost', email='cl@donotreply.com')
        d.author = a
        self.assertEqual(d.author, 'Nobody')
        self.assertFalse('Christian Ledermann' in str(d.to_string()))
        self.assertTrue('Nobody' in str(d.to_string()))
        self.assertTrue('http://localhost' in str(d.to_string()))
        self.assertTrue('cl@donotreply.com' in str(d.to_string()))
        d2 = kml.Document()
        d2.from_string(d.to_string())
        self.assertEqual(d.to_string(), d2.to_string())
        d.author = None
github cleder / fastkml / fastkml / test_main.py View on Github external
def test_feature_timespan_stamp(self):
        now = datetime.datetime.now()
        y2k = datetime.date(2000, 1, 1)
        f = kml.Document()
        f.begin = y2k
        f.end = now
        self.assertTrue(now.isoformat() in str(f.to_string()))
        self.assertTrue('2000-01-01' in str(f.to_string()))
        self.assertTrue('TimeSpan>' in str(f.to_string()))
        self.assertTrue('begin>' in str(f.to_string()))
        self.assertTrue('end>' in str(f.to_string()))
        self.assertFalse('TimeStamp>' in str(f.to_string()))
        self.assertFalse('when>' in str(f.to_string()))
        # when we set a timestamp an existing timespan will be deleted
        f.timeStamp = now
        self.assertTrue(now.isoformat() in str(f.to_string()))
        self.assertTrue('TimeStamp>' in str(f.to_string()))
        self.assertTrue('when>' in str(f.to_string()))
        self.assertFalse('2000-01-01' in str(f.to_string()))
        self.assertFalse('TimeSpan>' in str(f.to_string()))
github cleder / fastkml / fastkml / test_main.py View on Github external
def test_featurefromstring(self):
        d = kml.Document(ns='')
        doc = """
          Document.kml
          1
          
            1997-07-16T10:30:15+03:00
          
          
            1876-08-01
            1997-07-16T07:30:15Z
          
        """
        d.from_string(doc)
github cleder / fastkml / fastkml / test_main.py View on Github external
def test_create_document_style(self):
        style = styles.Style(styles=[styles.PolyStyle(color='7f000000')])

        doc = kml.Document(styles=[style])

        doc2 = kml.Document()
        doc2.append_style(style)

        expected = """
            
              1
                
                  
                    7f000000
                    1
                    1
                  
                
            
        """
github cleder / fastkml / fastkml / test_main.py View on Github external
def test_styleurl(self):
        f = kml.Document()
        f.styleUrl = '#somestyle'
        self.assertEqual(f.styleUrl, '#somestyle')
        self.assertTrue(isinstance(f._styleUrl, styles.StyleUrl))
        s = styles.StyleUrl(config.NS, url='#otherstyle')
        f.styleUrl = s
        self.assertTrue(isinstance(f._styleUrl, styles.StyleUrl))
        self.assertEqual(f.styleUrl, '#otherstyle')
        f2 = kml.Document()
        f2.from_string(f.to_string())
        self.assertEqual(f.to_string(), f2.to_string())
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
github cleder / fastkml / fastkml / test_main.py View on Github external
doc2 = kml.Document()
        doc2.append_style(style)

        expected = """
            
              1
                
                  
                    7f000000
                    1
                    1
                  
                
            
        """
        doc3 = kml.Document()
        doc3.from_string(expected)

        self.assertEqual(doc.to_string(), doc2.to_string())
        self.assertEqual(doc2.to_string(), doc3.to_string())
        self.assertEqual(doc.to_string(), doc3.to_string())
github cleder / fastkml / fastkml / test_main.py View on Github external
def test_style(self):
        lstyle = styles.LineStyle(color='red', width=2.0)
        style = styles.Style(styles=[lstyle])
        f = kml.Document(styles=[style])
        f2 = kml.Document()
        f2.from_string(f.to_string(prettyprint=True))
        self.assertEqual(f.to_string(), f2.to_string())