How to use the fastkml.kml.Placemark 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_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 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 / test_main.py View on Github external
place2 = kml.Placemark()
        place2.append_style(style)

        expected = """
            
              1
                
                  
                    7f000000
                    1
                    1
                  
                
            
        """
        place3 = kml.Placemark()
        place3.from_string(expected)
        self.assertEqual(place.to_string(), place2.to_string())
        self.assertEqual(place2.to_string(), place3.to_string())
        self.assertEqual(place.to_string(), place3.to_string())
github cleder / fastkml / fastkml / test_main.py View on Github external
def test_create_placemark_style(self):
        style = styles.Style(styles=[styles.PolyStyle(color='7f000000')])

        place = kml.Placemark(styles=[style])

        place2 = kml.Placemark()
        place2.append_style(style)

        expected = """
            
              1
                
                  
                    7f000000
                    1
                    1
                  
                
            
        """
        place3 = kml.Placemark()
        place3.from_string(expected)
github cleder / fastkml / fastkml / test_main.py View on Github external
def test_placemark(self):
        ns = '{http://www.opengis.net/kml/2.2}'
        k = kml.KML(ns=ns)
        p = kml.Placemark(ns, 'id', 'name', 'description')
        p.geometry = Point(0.0, 0.0, 0.0)
        p2 = kml.Placemark(ns, 'id2', 'name2', 'description2')
        p2.geometry = LineString([(0, 0, 0), (1, 1, 1)])
        k.append(p)
        k.append(p2)
        self.assertEqual(len(list(k.features())), 2)
        k2 = kml.KML()
        k2.from_string(k.to_string(prettyprint=True))
        self.assertEqual(k.to_string(), k2.to_string())
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 projecthorus / radiosonde_auto_rx / auto_rx / utils / log_to_kml.py View on Github external
# Define the Line and Polygon styles, which are used for the flight path, and the extrusions (if enabled)
    flight_track_line_style = fastkml.styles.LineStyle(
        ns=ns,
        color=track_color,
        width=track_width)

    flight_extrusion_style = fastkml.styles.PolyStyle(
        ns=ns,
        color=poly_color)

    flight_track_style = fastkml.styles.Style(
        ns=ns,
        styles=[flight_track_line_style, flight_extrusion_style])

    # Generate the Placemark which will contain the track data.
    flight_line = fastkml.kml.Placemark(
        ns=ns,
        id=placemark_id,
        name=name,
        styles=[flight_track_style])

    # Add the track data to the Placemark
    flight_line.geometry = fastkml.geometry.Geometry(
        ns=ns,
        geometry=_flight_geom,
        altitude_mode=_alt_mode,
        extrude=extrude,
        tessellate=tessellate)

    return flight_line
github xoolive / traffic / traffic / drawing / kml.py View on Github external
def _airspace_export_kml(
    sector: Airspace,
    styleUrl: Optional[kml.StyleUrl] = None,
    color: Optional[str] = None,
    alpha: float = .5,
) -> kml.Placemark:
    if color is not None:
        # the style will be set only if the kml.export context is open
        styleUrl = toStyle(color)
    folder = kml.Folder(name=sector.name, description=sector.type)
    for extr_p in sector:
        for elt in sector.decompose(extr_p):
            placemark = kml.Placemark(styleUrl=styleUrl)
            placemark.geometry = kml.Geometry(
                geometry=elt, altitude_mode="relativeToGround"
            )
            folder.append(placemark)
    return folder
github cleder / fastkml / fastkml / kml.py View on Github external
def from_element(self, element):
        super(Placemark, self).from_element(element)
        point = element.find('%sPoint' % self.ns)
        if point is not None:
            geom = Geometry(ns=self.ns)
            geom.from_element(point)
            self._geometry = geom
            return
        line = element.find('%sLineString' % self.ns)
        if line is not None:
            geom = Geometry(ns=self.ns)
            geom.from_element(line)
            self._geometry = geom
            return
        polygon = element.find('%sPolygon' % self.ns)
        if polygon is not None:
            geom = Geometry(ns=self.ns)
            geom.from_element(polygon)