def parse_timestamps(self): """ Update data from <time> elements found within the track """ alltimes = self.trk.findall(ns + 'trkseg/' + ns + 'trkpt/' + ns + 'time') starttime = parse_xml_date(alltimes[0].text).replace(tzinfo=None) endtime = parse_xml_date(alltimes[-1].text).replace(tzinfo=None) delta = self.tz.utcoffset(starttime, False) self.starttime = starttime + delta self.endtime = endtime + delta
def find_coordinates(self, dt): """ Find a coordinate for a given DateTime, used for tagging images """ lat = lon = None ele = 0.0 latx = lonx = elex = None for tid, tobj in self.tracks.iteritems(): if dt >= tobj.starttime and dt <= tobj.endtime: for p in tobj.get_points(): try: if latx is None: latx = float(p.get('lat')) lonx = float(p.get('lon')) elex = float(p.findtext(ns + 'ele')) t0 = parse_xml_date(p.findtext(ns + 'time')).replace(tzinfo=None) delta = self.tz.utcoffset(t0, False) t0 += delta if t0 > dt: lat = (latx + float(p.get('lat'))) / 2 lon = (lonx + float(p.get('lon'))) / 2 ele = (elex + float(p.findtext(ns + 'ele'))) / 2 break else: latx = float(p.get('lat')) lonx = float(p.get('lon')) elex = float(p.findtext(ns + 'ele')) except Exception: latx = lonx = elex = None pass return (lat,lon,ele)
def find_coordinates(self, dt): """ Find a coordinate for a given DateTime, used for tagging images """ lat = lon = None ele = 0.0 latx = lonx = elex = None for tid, tobj in self.tracks.iteritems(): if dt >= tobj.starttime and dt <= tobj.endtime: for p in tobj.get_points(): try: if latx is None: latx = float(p.get('lat')) lonx = float(p.get('lon')) elex = float(p.findtext(ns + 'ele')) t0 = parse_xml_date( p.findtext(ns + 'time')).replace(tzinfo=None) delta = self.tz.utcoffset(t0, False) t0 += delta if t0 > dt: lat = (latx + float(p.get('lat'))) / 2 lon = (lonx + float(p.get('lon'))) / 2 ele = (elex + float(p.findtext(ns + 'ele'))) / 2 break else: latx = float(p.get('lat')) lonx = float(p.get('lon')) elex = float(p.findtext(ns + 'ele')) except Exception: latx = lonx = elex = None pass return (lat, lon, ele)