Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
]
# Text fields serialize as empty container tags, dependents are
# are listed after as 'tag:dep1:dep2:dep3'. If no dependents are
# listed, it will always serialize. The container is closed with
# '/tag'. Required dependents are preceded by an @. If a required
# dependent is empty, nothing in the container will serialize. The
# format is 'tag:@dep2'. No optional dependents need to be listed.
# Extensions not yet supported
gpx_11_fields = [
mod_gpxfield.GPXField('version', attribute=True),
mod_gpxfield.GPXField('creator', attribute=True),
'metadata:name:description:author_name:author_email:author_link:copyright_author:copyright_year:copyright_license:link:time:keywords:bounds',
mod_gpxfield.GPXField('name', 'name'),
mod_gpxfield.GPXField('description', 'desc'),
'author:author_name:author_email:author_link',
mod_gpxfield.GPXField('author_name', 'name'),
mod_gpxfield.GPXEmailField('author_email', 'email'),
'link:@author_link',
mod_gpxfield.GPXField('author_link', attribute='href'),
mod_gpxfield.GPXField('author_link_text', tag='text'),
mod_gpxfield.GPXField('author_link_type', tag='type'),
'/link',
'/author',
'copyright:copyright_author:copyright_year:copyright_license',
mod_gpxfield.GPXField('copyright_author', attribute='author'),
mod_gpxfield.GPXField('copyright_year', tag='year'),
mod_gpxfield.GPXField('copyright_license', tag='license'),
'/copyright',
'link:@link',
mod_gpxfield.GPXField('link', attribute='href'),
mod_gpxfield.GPXField('link_text', tag='text'),
mod_gpxfield.GPXField('link_type', tag='type'),
mod_gpxfield.GPXField('version', attribute=True),
mod_gpxfield.GPXField('creator', attribute=True),
'metadata:name:description:author_name:author_email:author_link:copyright_author:copyright_year:copyright_license:link:time:keywords:bounds',
mod_gpxfield.GPXField('name', 'name'),
mod_gpxfield.GPXField('description', 'desc'),
'author:author_name:author_email:author_link',
mod_gpxfield.GPXField('author_name', 'name'),
mod_gpxfield.GPXEmailField('author_email', 'email'),
'link:@author_link',
mod_gpxfield.GPXField('author_link', attribute='href'),
mod_gpxfield.GPXField('author_link_text', tag='text'),
mod_gpxfield.GPXField('author_link_type', tag='type'),
'/link',
'/author',
'copyright:copyright_author:copyright_year:copyright_license',
mod_gpxfield.GPXField('copyright_author', attribute='author'),
mod_gpxfield.GPXField('copyright_year', tag='year'),
mod_gpxfield.GPXField('copyright_license', tag='license'),
'/copyright',
'link:@link',
mod_gpxfield.GPXField('link', attribute='href'),
mod_gpxfield.GPXField('link_text', tag='text'),
mod_gpxfield.GPXField('link_type', tag='type'),
'/link',
mod_gpxfield.GPXField('time', type=mod_gpxfield.TIME_TYPE),
mod_gpxfield.GPXField('keywords'),
mod_gpxfield.GPXComplexField('bounds', classs=GPXBounds),
mod_gpxfield.GPXExtensionsField('metadata_extensions', tag='extensions'),
'/metadata',
mod_gpxfield.GPXComplexField('waypoints', classs=GPXWaypoint, tag='wpt', is_list=True),
mod_gpxfield.GPXComplexField('routes', classs=GPXRoute, tag='rte', is_list=True),
mod_gpxfield.GPXComplexField('tracks', classs=GPXTrack, tag='trk', is_list=True),
mod_gpxfield.GPXField('time', type=mod_gpxfield.TIME_TYPE),
mod_gpxfield.GPXField('magnetic_variation', 'magvar', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('geoid_height', 'geoidheight', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('name'),
mod_gpxfield.GPXField('comment', 'cmt'),
mod_gpxfield.GPXField('description', 'desc'),
mod_gpxfield.GPXField('source', 'src'),
'link:@link',
mod_gpxfield.GPXField('link', attribute='href'),
mod_gpxfield.GPXField('link_text', tag='text'),
mod_gpxfield.GPXField('link_type', tag='type'),
'/link',
mod_gpxfield.GPXField('symbol', 'sym'),
mod_gpxfield.GPXField('type'),
mod_gpxfield.GPXField('type_of_gpx_fix', 'fix', possible=('none', '2d', '3d', 'dgps', 'pps',)),
mod_gpxfield.GPXField('satellites', 'sat', type=mod_gpxfield.INT_TYPE),
mod_gpxfield.GPXField('horizontal_dilution', 'hdop', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('vertical_dilution', 'vdop', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('position_dilution', 'pdop', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('age_of_dgps_data', 'ageofdgpsdata', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('dgps_id', 'dgpsid'),
mod_gpxfield.GPXExtensionsField('extensions', is_list=True),
]
# GPX1.0 track points have two more fields after time
# Note that this is not true for GPX1.1
GPX_TRACK_POINT_FIELDS = GPX_10_POINT_FIELDS[:4] \
+ [ \
mod_gpxfield.GPXField('course', type=mod_gpxfield.FLOAT_TYPE), \
mod_gpxfield.GPXField('speed', type=mod_gpxfield.FLOAT_TYPE) \
] \
+ GPX_10_POINT_FIELDS[4:]
'%Y-%m-%d %H:%M:%S.%f',
'%Y-%m-%d %H:%M:%S',
]
# Used in smoothing, sum must be 1:
SMOOTHING_RATIO = (0.4, 0.2, 0.4)
# When computing stopped time -- this is the minimum speed between two points,
# if speed is less than this value -- we'll assume it is zero
DEFAULT_STOPPED_SPEED_THRESHOLD = 1
# Fields used for all point elements (route point, track point, waypoint):
GPX_10_POINT_FIELDS = [
mod_gpxfield.GPXField('latitude', attribute='lat', type=mod_gpxfield.FLOAT_TYPE, mandatory=True),
mod_gpxfield.GPXField('longitude', attribute='lon', type=mod_gpxfield.FLOAT_TYPE, mandatory=True),
mod_gpxfield.GPXField('elevation', 'ele', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('time', type=mod_gpxfield.TIME_TYPE),
mod_gpxfield.GPXField('magnetic_variation', 'magvar', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('geoid_height', 'geoidheight', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('name'),
mod_gpxfield.GPXField('comment', 'cmt'),
mod_gpxfield.GPXField('description', 'desc'),
mod_gpxfield.GPXField('source', 'src'),
mod_gpxfield.GPXField('link', 'url'),
mod_gpxfield.GPXField('link_text', 'urlname'),
mod_gpxfield.GPXField('symbol', 'sym'),
mod_gpxfield.GPXField('type'),
mod_gpxfield.GPXField('type_of_gpx_fix', 'fix', possible=('none', '2d', '3d', 'dgps', 'pps',)),
mod_gpxfield.GPXField('satellites', 'sat', type=mod_gpxfield.INT_TYPE),
mod_gpxfield.GPXField('horizontal_dilution', 'hdop', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('vertical_dilution', 'vdop', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('position_dilution', 'pdop', type=mod_gpxfield.FLOAT_TYPE),
class GPXException(Exception):
"""
Exception used for invalid GPX files. It is used when the XML file is
valid but something is wrong with the GPX data.
"""
pass
class GPXBounds:
gpx_10_fields = gpx_11_fields = [
mod_gpxfield.GPXField('min_latitude', attribute='minlat', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('max_latitude', attribute='maxlat', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('min_longitude', attribute='minlon', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('max_longitude', attribute='maxlon', type=mod_gpxfield.FLOAT_TYPE),
]
__slots__ = ('min_latitude', 'max_latitude', 'min_longitude', 'max_longitude')
def __init__(self, min_latitude=None, max_latitude=None, min_longitude=None, max_longitude=None):
self.min_latitude = min_latitude
self.max_latitude = max_latitude
self.min_longitude = min_longitude
self.max_longitude = max_longitude
def __iter__(self):
return (self.min_latitude, self.max_latitude, self.min_longitude, self.max_longitude,).__iter__()
class GPXXMLSyntaxException(GPXException):
"""
mod_gpxfield.GPXComplexField('waypoints', classs=GPXWaypoint, tag='wpt', is_list=True),
mod_gpxfield.GPXComplexField('routes', classs=GPXRoute, tag='rte', is_list=True),
mod_gpxfield.GPXComplexField('tracks', classs=GPXTrack, tag='trk', is_list=True),
]
# Text fields serialize as empty container tags, dependents are
# are listed after as 'tag:dep1:dep2:dep3'. If no dependents are
# listed, it will always serialize. The container is closed with
# '/tag'. Required dependents are preceded by an @. If a required
# dependent is empty, nothing in the container will serialize. The
# format is 'tag:@dep2'. No optional dependents need to be listed.
# Extensions not yet supported
gpx_11_fields = [
mod_gpxfield.GPXField('version', attribute=True),
mod_gpxfield.GPXField('creator', attribute=True),
'metadata:name:description:author_name:author_email:author_link:copyright_author:copyright_year:copyright_license:link:time:keywords:bounds',
mod_gpxfield.GPXField('name', 'name'),
mod_gpxfield.GPXField('description', 'desc'),
'author:author_name:author_email:author_link',
mod_gpxfield.GPXField('author_name', 'name'),
mod_gpxfield.GPXEmailField('author_email', 'email'),
'link:@author_link',
mod_gpxfield.GPXField('author_link', attribute='href'),
mod_gpxfield.GPXField('author_link_text', tag='text'),
mod_gpxfield.GPXField('author_link_type', tag='type'),
'/link',
'/author',
'copyright:copyright_author:copyright_year:copyright_license',
mod_gpxfield.GPXField('copyright_author', attribute='author'),
mod_gpxfield.GPXField('copyright_year', tag='year'),
mod_gpxfield.GPXField('copyright_license', tag='license'),
'/copyright',
'link:@link',
mod_gpxfield.GPXField('type_of_gpx_fix', 'fix', possible=('none', '2d', '3d', 'dgps', 'pps',)),
mod_gpxfield.GPXField('satellites', 'sat', type=mod_gpxfield.INT_TYPE),
mod_gpxfield.GPXField('horizontal_dilution', 'hdop', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('vertical_dilution', 'vdop', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('position_dilution', 'pdop', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('age_of_dgps_data', 'ageofdgpsdata', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('dgps_id', 'dgpsid'),
]
GPX_11_POINT_FIELDS = [
# See GPX for description of text fields
mod_gpxfield.GPXField('latitude', attribute='lat', type=mod_gpxfield.FLOAT_TYPE, mandatory=True),
mod_gpxfield.GPXField('longitude', attribute='lon', type=mod_gpxfield.FLOAT_TYPE, mandatory=True),
mod_gpxfield.GPXField('elevation', 'ele', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('time', type=mod_gpxfield.TIME_TYPE),
mod_gpxfield.GPXField('magnetic_variation', 'magvar', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('geoid_height', 'geoidheight', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('name'),
mod_gpxfield.GPXField('comment', 'cmt'),
mod_gpxfield.GPXField('description', 'desc'),
mod_gpxfield.GPXField('source', 'src'),
'link:@link',
mod_gpxfield.GPXField('link', attribute='href'),
mod_gpxfield.GPXField('link_text', tag='text'),
mod_gpxfield.GPXField('link_type', tag='type'),
'/link',
mod_gpxfield.GPXField('symbol', 'sym'),
mod_gpxfield.GPXField('type'),
mod_gpxfield.GPXField('type_of_gpx_fix', 'fix', possible=('none', '2d', '3d', 'dgps', 'pps',)),
mod_gpxfield.GPXField('satellites', 'sat', type=mod_gpxfield.INT_TYPE),
mod_gpxfield.GPXField('horizontal_dilution', 'hdop', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('vertical_dilution', 'vdop', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('position_dilution', 'pdop', type=mod_gpxfield.FLOAT_TYPE),
# time are allowed, too:
DATE_FORMATS = [
'%Y-%m-%d %H:%M:%S.%f',
'%Y-%m-%d %H:%M:%S',
]
# Used in smoothing, sum must be 1:
SMOOTHING_RATIO = (0.4, 0.2, 0.4)
# When computing stopped time -- this is the minimum speed between two points,
# if speed is less than this value -- we'll assume it is zero
DEFAULT_STOPPED_SPEED_THRESHOLD = 1
# Fields used for all point elements (route point, track point, waypoint):
GPX_10_POINT_FIELDS = [
mod_gpxfield.GPXField('latitude', attribute='lat', type=mod_gpxfield.FLOAT_TYPE, mandatory=True),
mod_gpxfield.GPXField('longitude', attribute='lon', type=mod_gpxfield.FLOAT_TYPE, mandatory=True),
mod_gpxfield.GPXField('elevation', 'ele', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('time', type=mod_gpxfield.TIME_TYPE),
mod_gpxfield.GPXField('magnetic_variation', 'magvar', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('geoid_height', 'geoidheight', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('name'),
mod_gpxfield.GPXField('comment', 'cmt'),
mod_gpxfield.GPXField('description', 'desc'),
mod_gpxfield.GPXField('source', 'src'),
mod_gpxfield.GPXField('link', 'url'),
mod_gpxfield.GPXField('link_text', 'urlname'),
mod_gpxfield.GPXField('symbol', 'sym'),
mod_gpxfield.GPXField('type'),
mod_gpxfield.GPXField('type_of_gpx_fix', 'fix', possible=('none', '2d', '3d', 'dgps', 'pps',)),
mod_gpxfield.GPXField('satellites', 'sat', type=mod_gpxfield.INT_TYPE),
mod_gpxfield.GPXField('horizontal_dilution', 'hdop', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('satellites', 'sat', type=mod_gpxfield.INT_TYPE),
mod_gpxfield.GPXField('horizontal_dilution', 'hdop', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('vertical_dilution', 'vdop', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('position_dilution', 'pdop', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('age_of_dgps_data', 'ageofdgpsdata', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('dgps_id', 'dgpsid'),
]
GPX_11_POINT_FIELDS = [
# See GPX for description of text fields
mod_gpxfield.GPXField('latitude', attribute='lat', type=mod_gpxfield.FLOAT_TYPE, mandatory=True),
mod_gpxfield.GPXField('longitude', attribute='lon', type=mod_gpxfield.FLOAT_TYPE, mandatory=True),
mod_gpxfield.GPXField('elevation', 'ele', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('time', type=mod_gpxfield.TIME_TYPE),
mod_gpxfield.GPXField('magnetic_variation', 'magvar', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('geoid_height', 'geoidheight', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('name'),
mod_gpxfield.GPXField('comment', 'cmt'),
mod_gpxfield.GPXField('description', 'desc'),
mod_gpxfield.GPXField('source', 'src'),
'link:@link',
mod_gpxfield.GPXField('link', attribute='href'),
mod_gpxfield.GPXField('link_text', tag='text'),
mod_gpxfield.GPXField('link_type', tag='type'),
'/link',
mod_gpxfield.GPXField('symbol', 'sym'),
mod_gpxfield.GPXField('type'),
mod_gpxfield.GPXField('type_of_gpx_fix', 'fix', possible=('none', '2d', '3d', 'dgps', 'pps',)),
mod_gpxfield.GPXField('satellites', 'sat', type=mod_gpxfield.INT_TYPE),
mod_gpxfield.GPXField('horizontal_dilution', 'hdop', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('vertical_dilution', 'vdop', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('position_dilution', 'pdop', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('age_of_dgps_data', 'ageofdgpsdata', type=mod_gpxfield.FLOAT_TYPE),
('point', 'distance_from_start', 'track_no', 'segment_no', 'point_no'))
class GPXException(Exception):
"""
Exception used for invalid GPX files. It is used when the XML file is
valid but something is wrong with the GPX data.
"""
pass
class GPXBounds:
gpx_10_fields = gpx_11_fields = [
mod_gpxfield.GPXField('min_latitude', attribute='minlat', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('max_latitude', attribute='maxlat', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('min_longitude', attribute='minlon', type=mod_gpxfield.FLOAT_TYPE),
mod_gpxfield.GPXField('max_longitude', attribute='maxlon', type=mod_gpxfield.FLOAT_TYPE),
]
__slots__ = ('min_latitude', 'max_latitude', 'min_longitude', 'max_longitude')
def __init__(self, min_latitude=None, max_latitude=None, min_longitude=None, max_longitude=None):
self.min_latitude = min_latitude
self.max_latitude = max_latitude
self.min_longitude = min_longitude
self.max_longitude = max_longitude
def __iter__(self):
return (self.min_latitude, self.max_latitude, self.min_longitude, self.max_longitude,).__iter__()
class GPXXMLSyntaxException(GPXException):