Skip to content

Commit

Permalink
Updated gpxpy
Browse files Browse the repository at this point in the history
  • Loading branch information
kipe committed Jul 19, 2013
1 parent 7ce5099 commit 058cad3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
5 changes: 4 additions & 1 deletion gmapcatcher/gpxpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

def parse(xml_or_file, parser='lxml'):
def parse(xml_or_file, parser=None):
"""
Parse xml (string) or file object. This is just an wrapper for
GPXParser.parse() function.
parser may be 'lxml', 'minidom' or None (then it will be automatically
detected, lxml if possible).
"""

from . import gpx as mod_gpx
Expand Down
53 changes: 44 additions & 9 deletions gmapcatcher/gpxpy/gpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,13 @@ def get_bounds(self):
for track_segment in self.segments:
bounds = track_segment.get_bounds()

if not mod_utils.is_numeric(min_lat) or bounds.min_latitude < min_lat:
if not mod_utils.is_numeric(min_lat) or (bounds.min_latitude and bounds.min_latitude < min_lat):
min_lat = bounds.min_latitude
if not mod_utils.is_numeric(max_lat) or bounds.max_latitude > max_lat:
if not mod_utils.is_numeric(max_lat) or (bounds.max_latitude and bounds.max_latitude > max_lat):
max_lat = bounds.max_latitude
if not mod_utils.is_numeric(min_lon) or bounds.min_longitude < min_lon:
if not mod_utils.is_numeric(min_lon) or (bounds.min_longitude and bounds.min_longitude < min_lon):
min_lon = bounds.min_longitude
if not mod_utils.is_numeric(max_lon) or bounds.max_longitude > max_lon:
if not mod_utils.is_numeric(max_lon) or (bounds.max_longitude and bounds.max_longitude > max_lon):
max_lon = bounds.max_longitude

return Bounds(min_lat, max_lat, min_lon, max_lon)
Expand Down Expand Up @@ -628,6 +628,16 @@ def has_times(self):

return result

def has_elevations(self):
if not self.segments:
return None

result = True
for track_segment in self.segments:
result = result and track_segment.has_elevations()

return result

def get_nearest_location(self, location):
""" Returns (location, track_segment_no, track_point_no) for nearest location on track """
if not self.segments:
Expand Down Expand Up @@ -1074,17 +1084,31 @@ def has_times(self):
# ... or otherwise one empty track segment would change the entire
# track's "has_times" status!

has_first = self.points[0]
has_last = self.points[-1]

found = 0
for track_point in self.points:
if track_point.time:
found += 1

found = float(found) / float(len(self.points))
return len(self.points) > 2 and float(found) / float(len(self.points)) > .75

return has_first and found > .75 and has_last
def has_elevations(self):
"""
Returns if points in this segment contains timestamps.
At least the first, last points and 75% of others must have times fot this
method to return true.
"""
if not self.points:
return True
# ... or otherwise one empty track segment would change the entire
# track's "has_times" status!

found = 0
for track_point in self.points:
if track_point.elevation:
found += 1

return len(self.points) > 2 and float(found) / float(len(self.points)) > .75

def __hash__(self):
return mod_utils.hash_object(self, 'points')
Expand Down Expand Up @@ -1576,6 +1600,17 @@ def has_times(self):

return result

def has_elevations(self):
""" See GPXTrackSegment.has_times() """
if not self.tracks:
return None

result = True
for track in self.tracks:
result = result and track.has_elevations()

return result

def __hash__(self):
return mod_utils.hash_object(self, 'time', 'name', 'description', 'author', 'email', 'url', 'urlname', 'keywords', 'waypoints', 'routes', 'tracks', 'min_latitude', 'max_latitude', 'min_longitude', 'max_longitude')

Expand Down
3 changes: 3 additions & 0 deletions gmapcatcher/gpxpy/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
try:
import lxml.etree as mod_etree
except:
mod_etree = None
pass # LXML not available

from . import gpx as mod_gpx
Expand Down Expand Up @@ -90,6 +91,8 @@ class LXMLParser:
"""

def __init__(self, xml):
assert mod_etree

if mod_utils.PYTHON_VERSION[0] == '3':
# In python 3 all strings are unicode and for some reason lxml
# don't like unicode strings with XMLs declared as UTF-8:
Expand Down

0 comments on commit 058cad3

Please sign in to comment.