How to use the fastkml.config.etree.Element 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 / 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 / geometry.py View on Github external
def _etree_linearring(self, linearring):
        element = etree.Element("%sLinearRing" % self.ns)
        self._set_extrude(element)
        self._set_altitude_mode(element)
        # tesseleation is ignored by polygon and tesselation together with
        # LinearRing without a polygon very rare Edgecase -> ignore for now
        # if self.tessellate and self.altitude_mode in ['clampToGround',
        #        'clampToSeaFloor']:
        #    element.set('tessellate', '1')
        coords = list(linearring.coords)
        element.append(self._etree_coordinates(coords))
        return element
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 / geometry.py View on Github external
def _etree_multilinestring(self, linestrings):
        element = etree.Element("%sMultiGeometry" % self.ns)
        for linestring in linestrings.geoms:
            element.append(self._etree_linestring(linestring))
        return element
github cleder / fastkml / fastkml / geometry.py View on Github external
def _etree_polygon(self, polygon):
        element = etree.Element("%sPolygon" % self.ns)
        self._set_extrude(element)
        self._set_altitude_mode(element)
        outer_boundary = etree.SubElement(
            element, "%souterBoundaryIs" % self.ns
        )
        outer_boundary.append(self._etree_linearring(polygon.exterior))
        for ib in polygon.interiors:
            inner_boundary = etree.SubElement(
                element, "%sinnerBoundaryIs" % self.ns
            )
            inner_boundary.append(self._etree_linearring(ib))
        return element
github cleder / fastkml / fastkml / geometry.py View on Github external
def _etree_collection(self, features):
        element = etree.Element("%sMultiGeometry" % self.ns)
        for feature in features.geoms:
            if feature.geom_type == "Point":
                element.append(self._etree_point(feature))
            elif feature.geom_type == "LinearRing":
                element.append(self._etree_linearring(feature))
            elif feature.geom_type == "LineString":
                element.append(self._etree_linestring(feature))
            elif feature.geom_type == "Polygon":
                element.append(self._etree_polygon(feature))
            else:
                raise ValueError("Illegal geometry type.")
        return element