1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 03:35:53 +01:00

Prefer the map DEM for track/waypoints elevation if present

This commit is contained in:
Martin Tůma 2024-07-17 01:57:10 +02:00
parent be75165088
commit b6b64065fb
40 changed files with 84 additions and 72 deletions

View File

@ -39,12 +39,9 @@ HEADERS += src/common/config.h \
src/common/greatcircle.h \
src/common/programpaths.h \
src/common/tifffile.h \
src/common/downloader.h \
src/common/polygon.h \
src/common/color.h \
src/common/csv.h \
src/common/dem.h \
src/common/demloader.h \
src/GUI/crosshairitem.h \
src/GUI/motioninfoitem.h \
src/GUI/pluginparameters.h \
@ -122,6 +119,8 @@ HEADERS += src/common/config.h \
src/data/gpsdumpparser.h \
src/data/style.h \
src/data/twonavparser.h \
src/map/downloader.h \
src/map/demloader.h \
src/map/ENC/attributes.h \
src/map/ENC/mapdata.h \
src/map/ENC/atlasdata.h \
@ -196,6 +195,7 @@ HEADERS += src/common/config.h \
src/map/sqlitemap.h \
src/map/utm.h \
src/map/map.h \
src/map/dem.h \
src/map/maplist.h \
src/map/onlinemap.h \
src/map/tile.h \
@ -281,10 +281,7 @@ SOURCES += src/main.cpp \
src/common/greatcircle.cpp \
src/common/programpaths.cpp \
src/common/tifffile.cpp \
src/common/downloader.cpp \
src/common/csv.cpp \
src/common/dem.cpp \
src/common/demloader.cpp \
src/GUI/crosshairitem.cpp \
src/GUI/motioninfoitem.cpp \
src/GUI/pluginparameters.cpp \
@ -347,6 +344,8 @@ SOURCES += src/main.cpp \
src/GUI/pngexportdialog.cpp \
src/GUI/projectioncombobox.cpp \
src/GUI/passwordedit.cpp \
src/map/downloader.cpp \
src/map/demloader.cpp \
src/map/ENC/atlasdata.cpp \
src/map/ENC/mapdata.cpp \
src/map/ENC/rastertile.cpp \
@ -436,6 +435,7 @@ SOURCES += src/main.cpp \
src/map/geocentric.cpp \
src/map/jnxmap.cpp \
src/map/map.cpp \
src/map/dem.cpp \
src/map/geotiffmap.cpp \
src/map/image.cpp \
src/map/mbtilesmap.cpp \

View File

@ -13,8 +13,8 @@
#endif // Q_OS_ANDROID
#include "common/programpaths.h"
#include "common/config.h"
#include "common/downloader.h"
#include "common/dem.h"
#include "map/downloader.h"
#include "map/dem.h"
#include "map/ellipsoid.h"
#include "map/gcs.h"
#include "map/conversion.h"

View File

@ -39,8 +39,9 @@ void CadenceGraph::setInfo()
clearInfo();
}
QList<GraphItem*> CadenceGraph::loadData(const Data &data)
QList<GraphItem*> CadenceGraph::loadData(const Data &data, Map *map)
{
Q_UNUSED(map);
QList<GraphItem*> graphs;
for (int i = 0; i < data.tracks().count(); i++) {

View File

@ -14,7 +14,7 @@ public:
~CadenceGraph();
QString label() const {return tr("Cadence");}
QList<GraphItem*> loadData(const Data &data);
QList<GraphItem*> loadData(const Data &data, Map *map);
void clear();
void showTracks(bool show);

View File

@ -118,14 +118,14 @@ GraphItem *ElevationGraph::loadGraph(const Graph &graph, PathType type,
return gi;
}
QList<GraphItem*> ElevationGraph::loadData(const Data &data)
QList<GraphItem*> ElevationGraph::loadData(const Data &data, Map *map)
{
QList<GraphItem*> graphs;
GraphItem *primary, *secondary;
for (int i = 0; i < data.tracks().count(); i++) {
QColor color(_palette.nextColor());
const GraphPair &gp = data.tracks().at(i).elevation();
const GraphPair &gp = data.tracks().at(i).elevation(map);
primary = loadGraph(gp.primary(), TrackPath, color, true);
secondary = primary
@ -137,7 +137,7 @@ QList<GraphItem*> ElevationGraph::loadData(const Data &data)
}
for (int i = 0; i < data.routes().count(); i++) {
QColor color(_palette.nextColor());
const GraphPair &gp = data.routes().at(i).elevation();
const GraphPair &gp = data.routes().at(i).elevation(map);
primary = loadGraph(gp.primary(), RoutePath, color, true);
secondary = primary

View File

@ -14,7 +14,7 @@ public:
~ElevationGraph();
QString label() const {return tr("Elevation");}
QList<GraphItem*> loadData(const Data &data);
QList<GraphItem*> loadData(const Data &data, Map *map);
void clear();
void setUnits(enum Units units);
void showTracks(bool show);

View File

@ -43,8 +43,9 @@ void GearRatioGraph::setInfo()
clearInfo();
}
QList<GraphItem*> GearRatioGraph::loadData(const Data &data)
QList<GraphItem*> GearRatioGraph::loadData(const Data &data, Map *map)
{
Q_UNUSED(map);
QList<GraphItem*> graphs;
for (int i = 0; i < data.tracks().count(); i++) {

View File

@ -15,7 +15,7 @@ public:
~GearRatioGraph();
QString label() const {return tr("Gear ratio");}
QList<GraphItem*> loadData(const Data &data);
QList<GraphItem*> loadData(const Data &data, Map *map);
void clear();
void showTracks(bool show);

View File

@ -7,6 +7,7 @@
#include "units.h"
#include "timetype.h"
class Map;
class Data;
class GraphItem;
@ -24,7 +25,7 @@ public:
virtual ~GraphTab() {}
virtual QString label() const = 0;
virtual QList<GraphItem*> loadData(const Data &data) = 0;
virtual QList<GraphItem*> loadData(const Data &data, Map *map) = 0;
virtual void clear() {GraphView::clear();}
virtual void setUnits(enum Units units) {GraphView::setUnits(units);}
virtual void setGraphType(GraphType type) {GraphView::setGraphType(type);}

View File

@ -29,10 +29,10 @@
#include <QGeoPositionInfoSource>
#include "common/config.h"
#include "common/programpaths.h"
#include "common/downloader.h"
#include "common/demloader.h"
#include "data/data.h"
#include "data/poi.h"
#include "map/downloader.h"
#include "map/demloader.h"
#include "map/maplist.h"
#include "map/emptymap.h"
#include "map/crs.h"
@ -1145,7 +1145,7 @@ void GUI::loadData(const Data &data)
_pathName = QString();
for (int i = 0; i < _tabs.count(); i++)
graphs.append(_tabs.at(i)->loadData(data));
graphs.append(_tabs.at(i)->loadData(data, _map));
if (updateGraphTabs())
_splitter->refresh();
paths = _mapView->loadData(data);

View File

@ -39,8 +39,9 @@ void HeartRateGraph::setInfo()
clearInfo();
}
QList<GraphItem*> HeartRateGraph::loadData(const Data &data)
QList<GraphItem*> HeartRateGraph::loadData(const Data &data, Map *map)
{
Q_UNUSED(map);
QList<GraphItem*> graphs;
for (int i = 0; i < data.tracks().count(); i++) {

View File

@ -14,7 +14,7 @@ public:
~HeartRateGraph();
QString label() const {return tr("Heart rate");}
QList<GraphItem*> loadData(const Data &data);
QList<GraphItem*> loadData(const Data &data, Map *map);
void clear();
void showTracks(bool show);

View File

@ -39,8 +39,9 @@ void PowerGraph::setInfo()
clearInfo();
}
QList<GraphItem*> PowerGraph::loadData(const Data &data)
QList<GraphItem*> PowerGraph::loadData(const Data &data, Map *map)
{
Q_UNUSED(map);
QList<GraphItem*> graphs;
for (int i = 0; i < data.tracks().count(); i++) {

View File

@ -14,7 +14,7 @@ public:
~PowerGraph();
QString label() const {return tr("Power");}
QList<GraphItem*> loadData(const Data &data);
QList<GraphItem*> loadData(const Data &data, Map *map);
void clear();
void showTracks(bool show);

View File

@ -69,8 +69,9 @@ GraphItem *SpeedGraph::loadGraph(const Graph &graph, const Track &track,
return gi;
}
QList<GraphItem*> SpeedGraph::loadData(const Data &data)
QList<GraphItem*> SpeedGraph::loadData(const Data &data, Map *map)
{
Q_UNUSED(map);
QList<GraphItem*> graphs;
for (int i = 0; i < data.tracks().count(); i++) {

View File

@ -16,7 +16,7 @@ public:
~SpeedGraph();
QString label() const {return tr("Speed");}
QList<GraphItem*> loadData(const Data &data);
QList<GraphItem*> loadData(const Data &data, Map *map);
void clear();
void setUnits(Units units);
void setTimeType(TimeType type);

View File

@ -43,8 +43,9 @@ void TemperatureGraph::setInfo()
clearInfo();
}
QList<GraphItem*> TemperatureGraph::loadData(const Data &data)
QList<GraphItem*> TemperatureGraph::loadData(const Data &data, Map *map)
{
Q_UNUSED(map);
QList<GraphItem*> graphs;
for (int i = 0; i < data.tracks().count(); i++) {

View File

@ -14,7 +14,7 @@ public:
~TemperatureGraph();
QString label() const {return tr("Temperature");}
QList<GraphItem*> loadData(const Data &data);
QList<GraphItem*> loadData(const Data &data, Map *map);
void clear();
void setUnits(enum Units units);
void showTracks(bool show);

View File

@ -25,7 +25,7 @@ ToolTip WaypointItem::info() const
tt.insert(qApp->translate("WaypointItem", "Name"), _waypoint.name());
tt.insert(qApp->translate("WaypointItem", "Coordinates"),
Format::coordinates(_waypoint.coordinates(), _format));
QPair<qreal, qreal> elevations(_waypoint.elevations());
QPair<qreal, qreal> elevations(_waypoint.elevations(_map));
if (!std::isnan(elevations.first)) {
QString val = Format::elevation(elevations.first, _units);
if (!std::isnan(elevations.second))
@ -71,7 +71,7 @@ ToolTip WaypointItem::info() const
}
WaypointItem::WaypointItem(const Waypoint &waypoint, Map *map,
QGraphicsItem *parent) : GraphicsItem(parent)
QGraphicsItem *parent) : GraphicsItem(parent), _map(map)
{
_waypoint = waypoint;
_showLabel = false;
@ -93,6 +93,12 @@ WaypointItem::WaypointItem(const Waypoint &waypoint, Map *map,
setAcceptHoverEvents(true);
}
void WaypointItem::setMap(Map *map)
{
_map = map;
setPos(map->ll2xy(_waypoint.coordinates()));
}
void WaypointItem::updateCache()
{
QPainterPath p;

View File

@ -17,7 +17,7 @@ public:
const Waypoint &waypoint() const {return _waypoint;}
void setMap(Map *map) {setPos(map->ll2xy(_waypoint.coordinates()));}
void setMap(Map *map);
void setSize(int size);
void setColor(const QColor &color);
void showLabel(bool show);
@ -51,6 +51,8 @@ private:
Waypoint _waypoint;
Map *_map;
QColor _color;
int _size;
bool _showLabel;

View File

@ -1,4 +1,4 @@
#include "common/dem.h"
#include "map/map.h"
#include "route.h"
bool Route::_useDEM = false;
@ -49,19 +49,17 @@ Graph Route::gpsElevation() const
return graph;
}
Graph Route::demElevation() const
Graph Route::demElevation(Map *map) const
{
Graph graph;
QDateTime date;
GraphSegment gs(date);
DEM::lock();
for (int i = 0; i < _data.size(); i++) {
qreal dem = DEM::elevation(_data.at(i).coordinates());
qreal dem = map->elevation(_data.at(i).coordinates());
if (!std::isnan(dem))
gs.append(GraphPoint(_distance.at(i), NAN, dem));
}
DEM::unlock();
if (gs.size() >= 2)
graph.append(gs);
@ -72,18 +70,18 @@ Graph Route::demElevation() const
return graph;
}
GraphPair Route::elevation() const
GraphPair Route::elevation(Map *map) const
{
if (_useDEM) {
Graph dem(demElevation());
Graph dem(demElevation(map));
return (dem.isEmpty())
? GraphPair(gpsElevation(), Graph())
: GraphPair(dem, _show2ndElevation ? gpsElevation() : Graph());
} else {
Graph gps(gpsElevation());
return (gps.isEmpty())
? GraphPair(demElevation(), Graph())
: GraphPair(gps, _show2ndElevation ? demElevation() : Graph());
? GraphPair(demElevation(map), Graph())
: GraphPair(gps, _show2ndElevation ? demElevation(map) : Graph());
}
}

View File

@ -6,6 +6,8 @@
#include "graph.h"
#include "path.h"
class Map;
class Route
{
public:
@ -13,7 +15,7 @@ public:
const RouteData &data() const {return _data;}
Path path() const;
GraphPair elevation() const;
GraphPair elevation(Map *map) const;
qreal distance() const;
const QString &name() const {return _data.name();}
@ -30,7 +32,7 @@ public:
private:
Graph gpsElevation() const;
Graph demElevation() const;
Graph demElevation(Map *map) const;
RouteData _data;
QVector<qreal> _distance;

View File

@ -1,4 +1,4 @@
#include "common/dem.h"
#include "map/map.h"
#include "track.h"
@ -277,11 +277,10 @@ Graph Track::gpsElevation() const
return ret;
}
Graph Track::demElevation() const
Graph Track::demElevation(Map *map) const
{
Graph ret;
DEM::lock();
for (int i = 0; i < _data.size(); i++) {
const SegmentData &sd = _data.at(i);
if (sd.size() < 2)
@ -290,7 +289,7 @@ Graph Track::demElevation() const
GraphSegment gs(seg.start);
for (int j = 0; j < sd.size(); j++) {
qreal dem = DEM::elevation(sd.at(j).coordinates());
qreal dem = map->elevation(sd.at(j).coordinates());
if (std::isnan(dem) || seg.outliers.contains(j))
continue;
gs.append(GraphPoint(seg.distance.at(j), seg.time.at(j), dem));
@ -299,7 +298,6 @@ Graph Track::demElevation() const
if (gs.size() >= 2)
ret.append(filter(gs, _elevationWindow));
}
DEM::unlock();
if (_data.style().color().isValid())
ret.setColor(_data.style().color());
@ -307,18 +305,18 @@ Graph Track::demElevation() const
return ret;
}
GraphPair Track::elevation() const
GraphPair Track::elevation(Map *map) const
{
if (_useDEM) {
Graph dem(demElevation());
Graph dem(demElevation(map));
return (dem.isEmpty())
? GraphPair(gpsElevation(), Graph())
: GraphPair(dem, _show2ndElevation ? gpsElevation() : Graph());
} else {
Graph gps(gpsElevation());
return (gps.isEmpty())
? GraphPair(demElevation(), Graph())
: GraphPair(gps, _show2ndElevation ? demElevation() : Graph());
? GraphPair(demElevation(map), Graph())
: GraphPair(gps, _show2ndElevation ? demElevation(map) : Graph());
}
}

View File

@ -9,6 +9,7 @@
#include "graph.h"
#include "path.h"
class Map;
class Track
{
@ -17,7 +18,7 @@ public:
Path path() const;
GraphPair elevation() const;
GraphPair elevation(Map *map) const;
GraphPair speed() const;
Graph heartRate() const;
Graph temperature() const;
@ -68,7 +69,7 @@ private:
qreal lastTime(int seg);
bool discardStopPoint(const Segment &seg, int i) const;
Graph demElevation() const;
Graph demElevation(Map *map) const;
Graph gpsElevation() const;
Graph reportedSpeed() const;
Graph computedSpeed() const;

View File

@ -1,18 +1,16 @@
#include <QDir>
#include <QFileInfo>
#include "common/dem.h"
#include "map/map.h"
#include "waypoint.h"
bool Waypoint::_useDEM = false;
bool Waypoint::_show2ndElevation = false;
QHash<QString, QPixmap> Waypoint::_symbolIcons;
QPair<qreal, qreal> Waypoint::elevations() const
QPair<qreal, qreal> Waypoint::elevations(Map *map) const
{
if (_useDEM) {
DEM::lock();
qreal dem = DEM::elevation(coordinates());
DEM::unlock();
qreal dem = map->elevation(coordinates());
if (!std::isnan(dem))
return QPair<qreal, qreal>(dem, _show2ndElevation ? elevation()
: NAN);
@ -20,12 +18,10 @@ QPair<qreal, qreal> Waypoint::elevations() const
return QPair<qreal, qreal>(elevation(), NAN);
} else {
if (hasElevation()) {
DEM::lock();
qreal dem = _show2ndElevation ? DEM::elevation(coordinates()) : NAN;
DEM::unlock();
qreal dem = _show2ndElevation ? map->elevation(coordinates()) : NAN;
return QPair<qreal, qreal>(elevation(), dem);
} else
return QPair<qreal, qreal>(DEM::elevation(coordinates()), NAN);
return QPair<qreal, qreal>(map->elevation(coordinates()), NAN);
}
}

View File

@ -12,6 +12,8 @@
#include "link.h"
#include "style.h"
class Map;
class Waypoint
{
public:
@ -33,7 +35,7 @@ public:
qreal elevation() const {return _elevation;}
const PointStyle &style() const {return _style;}
QPair<qreal, qreal> elevations() const;
QPair<qreal, qreal> elevations(Map *map) const;
void setCoordinates(const Coordinates &coordinates)
{_coordinates = coordinates;}

View File

@ -1,7 +1,7 @@
#include <QFont>
#include <QPainter>
#include <QCache>
#include "common/dem.h"
#include "map/dem.h"
#include "map/textpathitem.h"
#include "map/textpointitem.h"
#include "map/bitmapline.h"

View File

@ -17,7 +17,7 @@
#include <QRegularExpression>
#include <QLocale>
#include <private/qzipreader_p.h>
#include "rectc.h"
#include "common/rectc.h"
#include "dem.h"

View File

@ -1,6 +1,6 @@
#include <cmath>
#include <QLineF>
#include "common/dem.h"
#include "dem.h"
#include "map.h"

View File

@ -1,7 +1,7 @@
#include <cmath>
#include <QPainter>
#include <QCache>
#include "common/dem.h"
#include "map/dem.h"
#include "map/rectd.h"
#include "map/hillshading.h"
#include "map/filter.h"

View File

@ -5,7 +5,7 @@
#include "common/range.h"
#include "common/rectc.h"
#include "common/kv.h"
#include "common/downloader.h"
#include "downloader.h"
#include "coordinatesystem.h"
class Map;

View File

@ -3,7 +3,7 @@
#include <QPixmapCache>
#include "common/rectc.h"
#include "common/programpaths.h"
#include "common/downloader.h"
#include "downloader.h"
#include "osm.h"
#include "onlinemap.h"

View File

@ -3,7 +3,7 @@
#include <QObject>
#include <QString>
#include "common/downloader.h"
#include "downloader.h"
#include "rectd.h"
class TileLoader : public QObject

View File

@ -6,7 +6,7 @@
#include "common/range.h"
#include "common/rectc.h"
#include "common/kv.h"
#include "common/downloader.h"
#include "downloader.h"
#include "projection.h"
#include "coordinatesystem.h"

View File

@ -9,7 +9,7 @@
#include "common/hash.h"
#include "common/rectc.h"
#include "common/kv.h"
#include "common/downloader.h"
#include "downloader.h"
#include "projection.h"
#include "coordinatesystem.h"