How to use the fastkml.styles.Style 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_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())
github cleder / fastkml / fastkml / test_main.py View on Github external
PolygonStyle.kml
          1
          
        
        """
        # XXX fill and outline
        k = kml.KML()
        k.from_string(doc)
        self.assertEqual(len(list(k.features())), 1)
        self.assertTrue(
            isinstance(list(list(k.features())[0].styles())[0], styles.Style)
        )
        style = list(list(list(k.features())[0].styles())[0].styles())[0]
        self.assertTrue(isinstance(style, styles.PolyStyle))
        self.assertEqual(style.color, 'ff0000cc')
        self.assertEqual(style.colorMode, 'random')
        k2 = kml.KML()
        k2.from_string(k.to_string())
        self.assertEqual(k.to_string(), k2.to_string())
github projecthorus / radiosonde_auto_rx / auto_rx / utils / log_to_kml.py View on Github external
absolute = False,
    icon = "http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png",
    scale = 1.0):
    """ Generate a generic placemark object """

    if absolute:
        _alt_mode = 'absolute'
    else:
        _alt_mode = 'clampToGround'

    flight_icon_style = fastkml.styles.IconStyle(
        ns=ns, 
        icon_href=icon, 
        scale=scale)

    flight_style = fastkml.styles.Style(
        ns=ns,
        styles=[flight_icon_style])

    flight_placemark = fastkml.kml.Placemark(
        ns=ns, 
        id=placemark_id,
        name=name,
        description="",
        styles=[flight_style])

    flight_placemark.geometry = fastkml.geometry.Geometry(
        ns=ns,
        geometry=Point(lon, lat, alt),
        altitude_mode=_alt_mode)

    return flight_placemark
github cleder / fastkml / fastkml / styles.py View on Github external
key = pair.find('%skey' % self.ns)
            style = pair.find('%sStyle' % self.ns)
            style_url = pair.find('%sstyleUrl' % self.ns)
            if key.text == "highlight":
                if style is not None:
                    highlight = Style(self.ns)
                    highlight.from_element(style)
                elif style_url is not None:
                    highlight = StyleUrl(self.ns)
                    highlight.from_element(style_url)
                else:
                    raise ValueError
                self.highlight = highlight
            elif key.text == "normal":
                if style is not None:
                    normal = Style(self.ns)
                    normal.from_element(style)
                elif style_url is not None:
                    normal = StyleUrl(self.ns)
                    normal.from_element(style_url)
                else:
                    raise ValueError
                self.normal = normal
            else:
                raise ValueError
github cleder / fastkml / fastkml / styles.py View on Github external
def from_element(self, element):
        super(StyleMap, self).from_element(element)
        pairs = element.findall('%sPair' % self.ns)
        for pair in pairs:
            key = pair.find('%skey' % self.ns)
            style = pair.find('%sStyle' % self.ns)
            style_url = pair.find('%sstyleUrl' % self.ns)
            if key.text == "highlight":
                if style is not None:
                    highlight = Style(self.ns)
                    highlight.from_element(style)
                elif style_url is not None:
                    highlight = StyleUrl(self.ns)
                    highlight.from_element(style_url)
                else:
                    raise ValueError
                self.highlight = highlight
            elif key.text == "normal":
                if style is not None:
                    normal = Style(self.ns)
                    normal.from_element(style)
                elif style_url is not None:
                    normal = StyleUrl(self.ns)
                    normal.from_element(style_url)
                else:
                    raise ValueError
github cleder / fastkml / fastkml / kml.py View on Github external
self.description = description.text
        visibility = element.find('%svisibility' % self.ns)
        if visibility is not None:
            if visibility.text in ['1', 'true']:
                self.visibility = 1
            else:
                self.visibility = 0
        isopen = element.find('%sopen' % self.ns)
        if isopen is not None:
            if isopen.text in ['1', 'true']:
                self.isopen = 1
            else:
                self.isopen = 0
        styles = element.findall('%sStyle' % self.ns)
        for style in styles:
            s = Style(self.ns)
            s.from_element(style)
            self.append_style(s)
        styles = element.findall('%sStyleMap' % self.ns)
        for style in styles:
            s = StyleMap(self.ns)
            s.from_element(style)
            self.append_style(s)
        style_url = element.find('%sstyleUrl' % self.ns)
        if style_url is not None:
            s = StyleUrl(self.ns)
            s.from_element(style_url)
            self._styleUrl = s
        snippet = element.find('%sSnippet' % self.ns)
        if snippet is not None:
            _snippet = {'text': snippet.text}
            if snippet.get('maxLines'):