How to use the gpxpy.utils function in gpxpy

To help you get started, we’ve selected a few gpxpy 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 tkrajina / gpxpy / gpxpy / parser.py View on Github external
schema_loc = mod_re.search(r'\sxsi:schemaLocation="[^"]+"', self.xml)
        if schema_loc:
            _, _, value = schema_loc.group(0).partition('=')
            self.gpx.schema_locations = value.strip('"').split()

        # Remove default namespace to simplify processing later
        self.xml = mod_re.sub(r"""\sxmlns=(['"])[^'"]+\1""", '', self.xml, count=1)

        # Build tree
        try:
            if GPXParser.__library() == "LXML":
                # lxml does not like unicode strings when it's expecting
                # UTF-8. Also, XML comments result in a callable .tag().
                # Strip them out to avoid handling them later.
                if mod_utils.PYTHON_VERSION[0] >= '3':
                    self.xml = self.xml.encode('utf-8')
                root = mod_etree.XML(self.xml,
                                     mod_etree.XMLParser(remove_comments=True))
            else:
                root = mod_etree.XML(self.xml)

        except Exception as e:
            # The exception here can be a lxml or ElementTree exception.
            log.debug('Error in:\n%s\n-----------\n' % self.xml, exc_info=True)

            # The library should work in the same way regardless of the
            # underlying XML parser that's why the exception thrown
            # here is GPXXMLSyntaxException (instead of simply throwing the
            # original ElementTree or lxml exception e).
            #
            # But, if the user needs the original exception (lxml or ElementTree)
github tkrajina / gpxpy / gpxpy / gpx.py View on Github external
if not first.time:
            first = self.points[1]

        last = self.points[-1]
        if not last.time:
            last = self.points[-2]

        if not last.time or not first.time:
            log.debug('Can\'t find time')
            return None

        if last.time < first.time:
            log.debug('Not enough time data')
            return None

        return mod_utils.total_seconds(last.time - first.time)
github tkrajina / gpxpy / gpxpy / gpxfield.py View on Github external
def to_xml(self, value, version, nsmap=None, prettyprint=True, indent=''):
        if value is None:
            return ''
        if not prettyprint:
            indent = ''
        if self.attribute:
            return '{0}="{1}"'.format(self.attribute, mod_utils.make_str(value))
        elif self.type_converter:
            value = self.type_converter.to_string(value)
        return mod_utils.to_xml(self.tag, content=value, escape=True,
                                prettyprint=prettyprint, indent=indent)
github tkrajina / gpxpy / gpxpy / geo.py View on Github external
def __hash__(self):
        return mod_utils.hash_object(self, ('latitude', 'longitude', 'elevation'))