• R/O
  • SSH

gpxviewer: Commit

GPX Viewer repository


Commit MetaInfo

Revisionfcf60cb07a0f799a23fb86323755d3d04592eae9 (tree)
Time2020-06-18 23:00:20
AuthorSergey Salnikov
CommiterSergey Salnikov

Log Message

* Fixed obtaining lat/lon data if non-standard format is used.
* Code refactored.

Change Summary

Incremental Difference

diff -r f3a0874521ca -r fcf60cb07a0f gpxviewer/gpxmainwindow.py
--- a/gpxviewer/gpxmainwindow.py Wed Jun 17 20:41:32 2020 +0700
+++ b/gpxviewer/gpxmainwindow.py Thu Jun 18 21:00:20 2020 +0700
@@ -466,38 +466,38 @@
466466
467467 @pyqtSlot()
468468 def showGoogleMap(self):
469- lat = TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LAT).data()
470- lon = TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LON).data()
469+ lat = str(TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LAT).data(gpx.ValueRole))
470+ lon = str(TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LON).data(gpx.ValueRole))
471471 webbrowser.open('https://maps.google.com/maps?ll=' + lat + ',' + lon + '&t=h&q=' + lat + ',' + lon + '&z=15')
472472
473473 @pyqtSlot()
474474 def showYandexMap(self):
475- lat = TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LAT).data()
476- lon = TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LON).data()
475+ lat = str(TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LAT).data(gpx.ValueRole))
476+ lon = str(TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LON).data(gpx.ValueRole))
477477 webbrowser.open('https://maps.yandex.ru?ll=' + lon + ',' + lat + '&spn=0.03,0.03&pt=' + lon + ',' + lat + '&l=sat')
478478
479479 @pyqtSlot()
480480 def showZoomEarthMap(self):
481- lat = TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LAT).data()
482- lon = TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LON).data()
481+ lat = str(TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LAT).data(gpx.ValueRole))
482+ lon = str(TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LON).data(gpx.ValueRole))
483483 webbrowser.open('https://zoom.earth/#' + lat + ',' + lon + ',15z,map')
484484
485485 @pyqtSlot()
486486 def showOpenCycleMap(self):
487- lat = TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LAT).data()
488- lon = TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LON).data()
487+ lat = str(TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LAT).data(gpx.ValueRole))
488+ lon = str(TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LON).data(gpx.ValueRole))
489489 webbrowser.open('https://openstreetmap.org/?mlat=' + lat + '&mlon=' + lon + '&zoom=15&layers=C')
490490
491491 @pyqtSlot()
492492 def showOpenTopoMap(self):
493- lat = TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LAT).data()
494- lon = TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LON).data()
493+ lat = str(TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LAT).data(gpx.ValueRole))
494+ lon = str(TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LON).data(gpx.ValueRole))
495495 webbrowser.open('https://opentopomap.org/#marker=15/' + lat + '/' + lon)
496496
497497 @pyqtSlot()
498498 def showTopoMap(self):
499- lat = TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LAT).data()
500- lon = TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LON).data()
499+ lat = str(TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LAT).data(gpx.ValueRole))
500+ lon = str(TheDocument.wptmodel.index(self.ui.wptView.currentIndex().data(gpx.IDRole), gpx.LON).data(gpx.ValueRole))
501501 webbrowser.open('http://loadmap.net/ru?q=' + lat + ' ' + lon + '&z=13&s=0')
502502
503503 @pyqtSlot()
diff -r f3a0874521ca -r fcf60cb07a0f gpxviewer/gpxmodel.py
--- a/gpxviewer/gpxmodel.py Wed Jun 17 20:41:32 2020 +0700
+++ b/gpxviewer/gpxmodel.py Thu Jun 18 21:00:20 2020 +0700
@@ -363,10 +363,7 @@
363363 else:
364364 self.parseGPXDocument(doc.getroot())
365365
366- TheConfig['ProfileStyle']['MinimumAltitude'] = str(
367- int(round(self.minalt, -3) - 500 if round(self.minalt, -3) > self.minalt else round(self.minalt, -3)))
368- TheConfig['ProfileStyle']['MaximumAltitude'] = str(
369- int(round(self.maxalt, -3) + 500 if round(self.maxalt, -3) < self.maxalt else round(self.maxalt, -3)))
366+ self.updateMinMaxAltitudes()
370367
371368 def parseGPXDocument(self, root):
372369 tag = 'name'
@@ -710,7 +707,7 @@
710707 if self.wptmodel.includeStates[j]:
711708 dt = (p[TIME_DAYS] - prev[TIME_DAYS]) * 24.0 if p[TIME_DAYS] != '' and prev[TIME_DAYS] != '' and prev[TIME_DAYS] != 0 else 0
712709 p[DIST_DELTA] = p[DIST] - prev[DIST]
713- p[ALT_DELTA] = p[ALT] - prev[ALT]
710+ p[ALT_DELTA] = int(self.wptmodel.index(p['ID'], ALT).data()) - int(self.wptmodel.index(prev['ID'], ALT).data())
714711 p[SPEED] = p[DIST_DELTA] / dt if dt != 0 else 0.0
715712 p[ALT_SPEED] = p[ALT_DELTA] / dt if dt != 0 else 0.0
716713 p[SLOPE] = p[ALT_DELTA] / p[DIST_DELTA] if p[DIST_DELTA] != 0 else 0.0
@@ -722,6 +719,16 @@
722719 p[ALT_SPEED] = ''
723720 p[SLOPE] = ''
724721
722+ def updateMinMaxAltitudes(self, alt=None):
723+ if alt is not None:
724+ self.minalt = min(self.minalt, alt)
725+ self.maxalt = max(self.maxalt, alt)
726+
727+ TheConfig['ProfileStyle']['MinimumAltitude'] = str(int(round(self.minalt, -3) - 500 if round(self.minalt, -3) > self.minalt
728+ else round(self.minalt, -3)))
729+ TheConfig['ProfileStyle']['MaximumAltitude'] = str(int(round(self.maxalt, -3) + 500 if round(self.maxalt, -3) < self.maxalt
730+ else round(self.maxalt, -3)))
731+
725732 def writeGPXFile(self, filename):
726733 ns = {None: 'http://www.topografix.com/GPX/1/1'}
727734 root = etree.Element('gpx', nsmap=ns, version='1.1', creator='GPX Viewer - https://osdn.net/projects/gpxviewer')
@@ -735,23 +742,20 @@
735742 for point, state in zip(self.wptmodel.waypoints, self.wptmodel.includeStates):
736743 if state:
737744 element = etree.SubElement(root, 'wpt', lat=str(point[LAT]), lon=str(point[LON]))
738- etree.SubElement(element, 'ele').text = str(point[ALT])
745+ etree.SubElement(element, 'ele').text = self.wptmodel.index(point['ID'], ALT).data()
739746 minlat = min(minlat, point[LAT])
740747 minlon = min(minlon, point[LON])
741748 maxlat = max(maxlat, point[LAT])
742749 maxlon = max(maxlon, point[LON])
743750 if point[TIME] != '':
744751 etree.SubElement(element, 'time').text = point[TIME].isoformat() + 'Z'
745- if point['ID'] in self.wptmodel.changedNames:
746- etree.SubElement(element, 'name').text = self.wptmodel.changedNames[point['ID']]
747- else:
748- etree.SubElement(element, 'name').text = point[NAME]
752+ etree.SubElement(element, 'name').text = self.wptmodel.index(point['ID'], NAME).data()
749753
750- if point['CMT'] is not None:
754+ if 'CMT' in point and point['CMT'] is not None:
751755 etree.SubElement(element, 'cmt').text = point['CMT']
752- if point['DESC'] is not None:
756+ if 'DESC' in point and point['DESC'] is not None:
753757 etree.SubElement(element, 'desc').text = point['DESC']
754- if point['SYM'] is not None:
758+ if 'SYM' in point and point['SYM'] is not None:
755759 etree.SubElement(element, 'sym').text = point['SYM']
756760
757761 for track, state in zip(self.trkmodel.tracks, self.trkmodel.includeStates):
@@ -813,15 +817,12 @@
813817 for point, state in zip(self.wptmodel.waypoints, self.wptmodel.includeStates):
814818 if state:
815819 place = etree.SubElement(wptfolder, 'Placemark')
816- if point['ID'] in self.wptmodel.changedNames:
817- etree.SubElement(place, 'name').text = self.wptmodel.changedNames[point['ID']]
818- else:
819- etree.SubElement(place, 'name').text = point[NAME]
820+ etree.SubElement(place, 'name').text = self.wptmodel.index(point['ID'], NAME).data()
820821 if point[TIME] != '':
821822 ts = etree.SubElement(place, 'TimeStamp')
822823 etree.SubElement(ts, 'when').text = point[TIME].isoformat() + 'Z'
823824 p = etree.SubElement(place, 'Point')
824- etree.SubElement(p, 'coordinates').text = str(point[LON]) + ',' + str(point[LAT]) + ',' + str(point[ALT])
825+ etree.SubElement(p, 'coordinates').text = str(point[LON]) + ',' + str(point[LAT]) + ',' + self.wptmodel.index(point['ID'], ALT).data()
825826
826827 for track, state in zip(self.trkmodel.tracks, self.trkmodel.includeStates):
827828 if state:
Show on old repository browser