How to use the fastkml.config 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_kml(self):
        """ kml file without contents """
        k = kml.KML()
        self.assertEqual(len(list(k.features())), 0)
        if config.LXML:
            self.assertEqual(
                str(k.to_string())[:43],
                ''[:43]
            )
        else:
            if hasattr(etree, 'register_namespace'):
                self.assertEqual(
                    str(k.to_string())[:51],
                    ''[:51]
                )
            else:
                self.assertEqual(
                    str(k.to_string())[:51],
                    ''[:51]
                )
github cleder / fastkml / fastkml / test_main.py View on Github external
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
        # p3.altitudeMode = 'absolute'
        self.assertNotEqual(p2.to_string(), p3.to_string())
        config.FORCE3D = True
        self.assertEqual(p2.to_string(), p3.to_string())
        # altitudeMode clampToGround indicates to ignore an altitude specification.
        # p3.altitudeMode = 'clampToGround'
        # self.assertEqual(p2.to_string(), p3.to_string())
        # config.FORCE3D = False
        # self.assertNotEqual(p2.to_string(), p3.to_string())

        # Important: Set FORCE3D back to False!
        config.FORCE3D = False
github cleder / fastkml / fastkml / base.py View on Github external
def to_string(self, prettyprint=True):
        """ Return the KML Object as serialized xml """
        if config.LXML and prettyprint:
            return etree.tostring(
                self.etree_element(),
                encoding='utf-8',
                pretty_print=True).decode('UTF-8')
        else:
            return etree.tostring(
                self.etree_element(),
                encoding='utf-8').decode('UTF-8')
github cleder / fastkml / fastkml / geometry.py View on Github external
def _etree_coordinates(self, coordinates):
        # clampToGround = (
        #     (self.altitude_mode == 'clampToGround')
        #     or (self.altitude_mode is None)
        # )
        element = etree.Element("%scoordinates" % self.ns)
        if len(coordinates[0]) == 2:
            if config.FORCE3D:  # and not clampToGround:
                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:
            # if clampToGround:
                # if the altitude is ignored anyway, we may as well
                # ignore the z-value
            #    tuples = ('%f,%f' % tuple(c[:2]) for c in coordinates)
            # else:
            tuples = ('%f,%f,%f' % tuple(c) for c in coordinates)
        else:
            raise ValueError("Invalid dimensions")
        element.text = ' '.join(tuples)
        return element
github cleder / fastkml / fastkml / kml.py View on Github external
def __init__(self, ns=None):
        """ The namespace (ns) may be empty ('') if the 'kml:' prefix is
        undesired. Note that all child elements like Document or Placemark need
        to be initialized with empty namespace as well in this case.

        """
        self._features = []

        if ns is None:
            self.ns = config.KMLNS
        else:
            self.ns = ns
github cleder / fastkml / fastkml / base.py View on Github external
def __init__(self, ns=None, id=None):
        super(_BaseObject, self).__init__(ns)
        self.id = id
        if ns is None:
            self.ns = config.KMLNS
        else:
            self.ns = ns
github cleder / fastkml / fastkml / kml.py View on Github external
def etree_element(self):
        # self.ns may be empty, which leads to unprefixed kml elements.
        # However, in this case the xlmns should still be mentioned on the kml
        # element, just without prefix.
        if not self.ns:
            root = etree.Element('%skml' % self.ns)
            root.set('xmlns', config.KMLNS[1:-1])
        else:
            if config.LXML:
                root = etree.Element(
                    '%skml' % self.ns,
                    nsmap={None: self.ns[1:-1]}
                )
            else:
                root = etree.Element('%skml' % self.ns)
        for feature in self.features():
            root.append(feature.etree_element())
        return root
github cleder / fastkml / fastkml / base.py View on Github external
def __init__(self, ns=None):
        if ns is None:
            self.ns = config.KMLNS
        else:
            self.ns = ns