How to use the fastkml.base._BaseObject 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_BaseObject(self):
        bo = base._BaseObject(id='id0')
        self.assertEqual(bo.id, 'id0')
        self.assertEqual(bo.ns, config.NS)
        self.assertEqual(bo.targetId, None)
        self.assertEqual(bo.__name__, None)
        bo.targetId = 'target'
        self.assertEqual(bo.targetId, 'target')
        bo.ns = ''
        bo.id = None
        self.assertEqual(bo.id, None)
        self.assertEqual(bo.ns, '')
        self.assertRaises(NotImplementedError, bo.etree_element)
        element = etree.Element(config.NS + 'Base')
        self.assertRaises(TypeError, bo.from_element)
        self.assertRaises(TypeError, bo.from_element, element)
        bo.__name__ = 'NotABaseObject'
        self.assertRaises(TypeError, bo.from_element, element)
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 / geometry.py View on Github external
from pygeoif.geometry import LinearRing
    from pygeoif.geometry import GeometryCollection
    from pygeoif.geometry import as_shape as asShape

import re
import fastkml.config as config

from .config import etree

from .base import _BaseObject

import logging
logger = logging.getLogger('fastkml.geometry')


class Geometry(_BaseObject):
    """

    """
    __name__ = None
    geometry = None
    extrude = False
    tessellate = False
    altitude_mode = None

    def __init__(
        self, ns=None, id=None, geometry=None, extrude=False,
        tessellate=False, altitude_mode=None
    ):
        """
        geometry: a geometry that implements the __geo_interface__ convention
github cleder / fastkml / fastkml / kml.py View on Github external
return

        logger.warn('No geometries found')
        logger.debug(u'Problem with element: {}'.format(etree.tostring(element)))
        #raise ValueError('No geometries found')

    def etree_element(self):
        element = super(Placemark, self).etree_element()
        if self._geometry is not None:
            element.append(self._geometry.etree_element())
        else:
            logger.error('Object does not have a geometry')
        return element


class _TimePrimitive(_BaseObject):
    """ The dateTime is defined according to XML Schema time.
    The value can be expressed as yyyy-mm-ddThh:mm:sszzzzzz, where T is
    the separator between the date and the time, and the time zone is
    either Z (for UTC) or zzzzzz, which represents ±hh:mm in relation to
    UTC. Additionally, the value can be expressed as a date only.

    The precision of the dateTime is dictated by the dateTime value
    which can be one of the following:

    - dateTime gives second resolution
    - date gives day resolution
    - gYearMonth gives month resolution
    - gYear gives year resolution
    """

    RESOLUTIONS = ['gYear', 'gYearMonth', 'date', 'dateTime']
github cleder / fastkml / fastkml / styles.py View on Github external
def etree_element(self):
        element = super(LabelStyle, self).etree_element()
        if self.scale is not None:
            scale = etree.SubElement(element, "%sscale" % self.ns)
            scale.text = str(self.scale)
        return element

    def from_element(self, element):
        super(LabelStyle, self).from_element(element)
        scale = element.find('%sscale' % self.ns)
        if scale is not None:
            self.scale = float(scale.text)


class BalloonStyle(_BaseObject):
    """ Specifies how the description balloon for placemarks is drawn.
        The , if specified, is used as the background color of
        the balloon."""

    __name__ = "BalloonStyle"

    bgColor = None
    # Background color of the balloon (optional). Color and opacity (alpha)
    # values are expressed in hexadecimal notation. The range of values for
    # any one color is 0 to 255 (00 to ff). The order of expression is
    # aabbggrr, where aa=alpha (00 to ff); bb=blue (00 to ff);
    # gg=green (00 to ff); rr=red (00 to ff).
    # For alpha, 00 is fully transparent and ff is fully opaque.
    # For example, if you want to apply a blue color with 50 percent
    # opacity to an overlay, you would specify the following:
    # 7fff0000, where alpha=0x7f, blue=0xff, green=0x00,
github cleder / fastkml / fastkml / styles.py View on Github external
self.url = url

    def etree_element(self):
        if self.url:
            element = super(StyleUrl, self).etree_element()
            element.text = self.url
            return element
        else:
            raise ValueError('No url given for styleUrl')

    def from_element(self, element):
        super(StyleUrl, self).from_element(element)
        self.url = element.text


class _StyleSelector(_BaseObject):
    """
    This is an abstract element and cannot be used directly in a KML file.
    It is the base type for the 
github cleder / fastkml / fastkml / kml.py View on Github external
text = self.date_to_string(*self.begin)
            if text:
                begin = etree.SubElement(element, "%sbegin" % self.ns)
                begin.text = text
        if self.end is not None:
            text = self.date_to_string(*self.end)
            if text:
                end = etree.SubElement(element, "%send" % self.ns)
                end.text = text
        if self.begin == self.end is None:
            raise ValueError("Either begin, end or both must be set")
        # TODO test if end > begin
        return element


class Schema(_BaseObject):
    """
    Specifies a custom KML schema that is used to add custom data to
    KML Features.
    The "id" attribute is required and must be unique within the KML file.
     is always a child of .
    """
    __name__ = "Schema"

    _simple_fields = None
    # The declaration of the custom fields, each of which must specify both the
    # type and the name of this field. If either the type or the name is
    # omitted, the field is ignored.
    name = None

    def __init__(self, ns=None, id=None, name=None, fields=None):
        if id is None:
github cleder / fastkml / fastkml / kml.py View on Github external
else:
                raise TypeError(
                    "Features must be instances of "
                    "(Document, Folder, Placemark)"
                )

    def append(self, kmlobj):
        """ append a feature """
        if isinstance(kmlobj, (Document, Folder, Placemark)):
            self._features.append(kmlobj)
        else:
            raise TypeError(
                "Features must be instances of (Document, Folder, Placemark)")


class _Feature(_BaseObject):
    """
    abstract element; do not create
    subclasses are:
        * Container (Document, Folder)
        * Placemark
        * Overlay
    Not Implemented Yet:
        * NetworkLink
    """
    name = None
    # User-defined text displayed in the 3D viewer as the label for the
    # object (for example, for a Placemark, Folder, or NetworkLink).

    visibility = 1
    # Boolean value. Specifies whether the feature is drawn in the 3D
    # viewer when it is initially loaded. In order for a feature to be
github cleder / fastkml / fastkml / styles.py View on Github external
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA

"""
Once you've created features within Google Earth and examined the KML
code Google Earth generates, you'll notice how styles are an important
part of how your data is displayed.
"""

import logging
logger = logging.getLogger('fastkml.styles')

from fastkml.config import etree
from fastkml.base import _BaseObject


class StyleUrl(_BaseObject):
    """
    URL of a