How to use the fastkml.kml.Folder 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_folder(self):
        """ KML file with folders """
        ns = '{http://www.opengis.net/kml/2.2}'
        k = kml.KML()
        f = kml.Folder(ns, 'id', 'name', 'description')
        nf = kml.Folder(ns, 'nested-id', 'nested-name', 'nested-description')
        f.append(nf)
        k.append(f)
        f2 = kml.Folder(ns, 'id2', 'name2', 'description2')
        k.append(f2)
        self.assertEqual(len(list(k.features())), 2)
        self.assertEqual(len(list(list(k.features())[0].features())), 1)
        k2 = kml.KML()
        s = k.to_string()
        k2.from_string(s)
        self.assertEqual(s, k2.to_string())
github cleder / fastkml / fastkml / test_main.py View on Github external
def test_folder(self):
        """ KML file with folders """
        ns = '{http://www.opengis.net/kml/2.2}'
        k = kml.KML()
        f = kml.Folder(ns, 'id', 'name', 'description')
        nf = kml.Folder(ns, 'nested-id', 'nested-name', 'nested-description')
        f.append(nf)
        k.append(f)
        f2 = kml.Folder(ns, 'id2', 'name2', 'description2')
        k.append(f2)
        self.assertEqual(len(list(k.features())), 2)
        self.assertEqual(len(list(list(k.features())[0].features())), 1)
        k2 = kml.KML()
        s = k.to_string()
        k2.from_string(s)
        self.assertEqual(s, k2.to_string())
github cleder / fastkml / fastkml / test_main.py View on Github external
def test_document(self):
        k = kml.KML()
        ns = '{http://www.opengis.net/kml/2.2}'
        d = kml.Document(ns, 'docid', 'doc name', 'doc description')
        f = kml.Folder(ns, 'fid', 'f name', 'f description')
        k.append(d)
        d.append(f)
        nf = kml.Folder(ns, 'nested-fid', 'nested f name', 'nested f description')
        f.append(nf)
        f2 = kml.Folder(ns, 'id2', 'name2', 'description2')
        d.append(f2)
        p = kml.Placemark(ns, 'id', 'name', 'description')
        p.geometry = Polygon([(0, 0, 0), (1, 1, 0), (1, 0, 1)])
        p2 = kml.Placemark(ns, 'id2', 'name2', 'description2')
        # p2 does not have a geometry!
        f2.append(p)
        nf.append(p2)
        self.assertEqual(len(list(k.features())), 1)
        self.assertEqual(len(list((list(k.features())[0].features()))), 2)
        k2 = kml.KML()
        k2.from_string(k.to_string())
github cleder / fastkml / fastkml / test_main.py View on Github external
def test_document(self):
        k = kml.KML()
        ns = '{http://www.opengis.net/kml/2.2}'
        d = kml.Document(ns, 'docid', 'doc name', 'doc description')
        f = kml.Folder(ns, 'fid', 'f name', 'f description')
        k.append(d)
        d.append(f)
        nf = kml.Folder(ns, 'nested-fid', 'nested f name', 'nested f description')
        f.append(nf)
        f2 = kml.Folder(ns, 'id2', 'name2', 'description2')
        d.append(f2)
        p = kml.Placemark(ns, 'id', 'name', 'description')
        p.geometry = Polygon([(0, 0, 0), (1, 1, 0), (1, 0, 1)])
        p2 = kml.Placemark(ns, 'id2', 'name2', 'description2')
        # p2 does not have a geometry!
        f2.append(p)
        nf.append(p2)
        self.assertEqual(len(list(k.features())), 1)
        self.assertEqual(len(list((list(k.features())[0].features()))), 2)
        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
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

        self.assertEqual(document_data.elements[0].name, 'type')
        self.assertEqual(document_data.elements[0].value, 'Document')
github projecthorus / radiosonde_auto_rx / auto_rx / utils / log_to_kml.py View on Github external
_first_line = _flight_data[0][4]
    _flight_serial = _first_line.split(',')[1] # Serial number is the second field in the line.
    _launch_time = _flight_data[0][0].strftime("%Y%m%d-%H%M%SZ")
    # Generate a comment line to use in the folder and placemark descriptions
    _track_comment = "%s %s" % (_launch_time, _flight_serial)
    _landing_comment = "%s Last Position" % (_flight_serial)

    # Grab burst and last-seen positions
    _burst_pos = flight_burst_position(_flight_data)
    _landing_pos = _flight_data[-1]

    # Generate the placemark & flight track.
    _flight_geom = flight_path_to_geometry(_flight_data, name=_track_comment, absolute=absolute, tessellate=tessellate, extrude=tessellate)
    _landing_geom = new_placemark(_landing_pos[1], _landing_pos[2], _landing_pos[3], name=_landing_comment, absolute=absolute)

    _folder = fastkml.kml.Folder(ns, _flight_serial, _track_comment, 'Radiosonde Flight Path')
    if last_only == False:
        _folder.append(_flight_geom)
    _folder.append(_landing_geom)

    return _folder
github cleder / fastkml / fastkml / kml.py View on Github external
xml_string,
                parser=etree.XMLParser(huge_tree=True)
            )
        else:
            element = etree.XML(xml_string)

        if element.tag.endswith('kml'):
            ns = element.tag.rstrip('kml')
            documents = element.findall('%sDocument' % ns)
            for document in documents:
                feature = Document(ns)
                feature.from_element(document)
                self.append(feature)
            folders = element.findall('%sFolder' % ns)
            for folder in folders:
                feature = Folder(ns)
                feature.from_element(folder)
                self.append(feature)
            placemarks = element.findall('%sPlacemark' % ns)
            for placemark in placemarks:
                feature = Placemark(ns)
                feature.from_element(placemark)
                self.append(feature)
        else:
            raise TypeError
github cleder / fastkml / fastkml / kml.py View on Github external
def from_element(self, element):
        super(Folder, self).from_element(element)
        folders = element.findall('%sFolder' % self.ns)
        for folder in folders:
            feature = Folder(self.ns)
            feature.from_element(folder)
            self.append(feature)
        placemarks = element.findall('%sPlacemark' % self.ns)
        for placemark in placemarks:
            feature = Placemark(self.ns)
            feature.from_element(placemark)
            self.append(feature)
        documents = element.findall('%sDocument' % self.ns)
        for document in documents:
            feature = Document(self.ns)
            feature.from_element(document)
            self.append(feature)