1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 05:34:47 +01:00

Enable DEM elevation for all data types (waypoints, routes)

This commit is contained in:
Martin Tůma 2019-01-17 00:47:44 +01:00
parent b8a2b76d7c
commit bd4af8c7e5
10 changed files with 71 additions and 26 deletions

View File

@ -12,7 +12,7 @@
#include "map/ellipsoid.h" #include "map/ellipsoid.h"
#include "map/gcs.h" #include "map/gcs.h"
#include "map/pcs.h" #include "map/pcs.h"
#include "data/track.h" #include "data/dem.h"
#include "opengl.h" #include "opengl.h"
#include "gui.h" #include "gui.h"
#include "settings.h" #include "settings.h"
@ -65,8 +65,7 @@ App::App(int &argc, char **argv) : QApplication(argc, argv)
OPENGL_SET_SAMPLES(4); OPENGL_SET_SAMPLES(4);
loadDatums(); loadDatums();
loadPCSs(); loadPCSs();
DEM::setDir(ProgramPaths::demDir());
Track::setDEMDir(ProgramPaths::demDir());
_gui = new GUI(); _gui = new GUI();
} }

View File

@ -875,6 +875,11 @@ void GUI::openOptions()
Track::action(options.option); \ Track::action(options.option); \
reload = true; \ reload = true; \
} }
#define SET_DATA_OPTION(option, action) \
if (options.option != _options.option) { \
Data::action(options.option); \
reload = true; \
}
Options options(_options); Options options(_options);
bool reload = false; bool reload = false;
@ -913,7 +918,7 @@ void GUI::openOptions()
SET_TRACK_OPTION(pauseSpeed, setPauseSpeed); SET_TRACK_OPTION(pauseSpeed, setPauseSpeed);
SET_TRACK_OPTION(pauseInterval, setPauseInterval); SET_TRACK_OPTION(pauseInterval, setPauseInterval);
SET_TRACK_OPTION(useReportedSpeed, useReportedSpeed); SET_TRACK_OPTION(useReportedSpeed, useReportedSpeed);
SET_TRACK_OPTION(useDEMElevation, useDEMElevation); SET_DATA_OPTION(useDEMElevation, useDEMElevation);
if (options.poiRadius != _options.poiRadius) if (options.poiRadius != _options.poiRadius)
_poi->setRadius(options.poiRadius); _poi->setRadius(options.poiRadius);
@ -2077,7 +2082,7 @@ void GUI::readSettings()
Track::setPauseSpeed(_options.pauseSpeed); Track::setPauseSpeed(_options.pauseSpeed);
Track::setPauseInterval(_options.pauseInterval); Track::setPauseInterval(_options.pauseInterval);
Track::useReportedSpeed(_options.useReportedSpeed); Track::useReportedSpeed(_options.useReportedSpeed);
Track::useDEMElevation(_options.useDEMElevation); Data::useDEMElevation(_options.useDEMElevation);
_poi->setRadius(_options.poiRadius); _poi->setRadius(_options.poiRadius);

View File

@ -11,6 +11,7 @@
#include "oziparsers.h" #include "oziparsers.h"
#include "locparser.h" #include "locparser.h"
#include "slfparser.h" #include "slfparser.h"
#include "dem.h"
#include "data.h" #include "data.h"
@ -49,6 +50,7 @@ static QHash<QString, Parser*> parsers()
QHash<QString, Parser*> Data::_parsers = parsers(); QHash<QString, Parser*> Data::_parsers = parsers();
bool Data::_useDEMElevation = false;
Data::~Data() Data::~Data()
{ {
@ -64,6 +66,13 @@ void Data::processData()
_tracks.append(new Track(_trackData.at(i))); _tracks.append(new Track(_trackData.at(i)));
for (int i = 0; i < _routeData.count(); i++) for (int i = 0; i < _routeData.count(); i++)
_routes.append(new Route(_routeData.at(i))); _routes.append(new Route(_routeData.at(i)));
for (int i = 0; i < _waypoints.size(); i++) {
if (!_waypoints.at(i).hasElevation() || _useDEMElevation) {
qreal elevation = DEM::elevation(_waypoints.at(i).coordinates());
if (!std::isnan(elevation))
_waypoints[i].setElevation(elevation);
}
}
} }
bool Data::loadFile(const QString &fileName) bool Data::loadFile(const QString &fileName)
@ -134,3 +143,10 @@ QStringList Data::filter()
return filter; return filter;
} }
void Data::useDEMElevation(bool use)
{
_useDEMElevation = use;
Route::useDEMElevation(use);
Track::useDEMElevation(use);
}

View File

@ -32,6 +32,8 @@ public:
static QString formats(); static QString formats();
static QStringList filter(); static QStringList filter();
static void useDEMElevation(bool use);
private: private:
void processData(); void processData();
@ -46,6 +48,7 @@ private:
QList<RouteData> _routeData; QList<RouteData> _routeData;
static QHash<QString, Parser*> _parsers; static QHash<QString, Parser*> _parsers;
static bool _useDEMElevation;
}; };
#endif // DATA_H #endif // DATA_H

View File

@ -1,4 +1,6 @@
#include <QtEndian> #include <QtEndian>
#include <QDir>
#include <QFile>
#include "common/coordinates.h" #include "common/coordinates.h"
#include "dem.h" #include "dem.h"
@ -48,7 +50,11 @@ static qreal height(const Coordinates &c, const QByteArray data)
return interpolate(dx, dy, p0, p1, p2, p3); return interpolate(dx, dy, p0, p1, p2, p3);
} }
QString DEM::fileName(const Key &key) const
QString DEM::_dir;
QMap<DEM::Key, QByteArray> DEM::_data;
QString DEM::fileName(const Key &key)
{ {
const char ns = (key.lat >= 0) ? 'N' : 'S'; const char ns = (key.lat >= 0) ? 'N' : 'S';
const char ew = (key.lon >= 0) ? 'E' : 'W'; const char ew = (key.lon >= 0) ? 'E' : 'W';
@ -59,6 +65,11 @@ QString DEM::fileName(const Key &key) const
return QDir(_dir).absoluteFilePath(basename); return QDir(_dir).absoluteFilePath(basename);
} }
void DEM::setDir(const QString &path)
{
_dir = path;
}
qreal DEM::elevation(const Coordinates &c) qreal DEM::elevation(const Coordinates &c)
{ {
if (_dir.isEmpty()) if (_dir.isEmpty())

View File

@ -1,19 +1,18 @@
#ifndef DEM_H #ifndef DEM_H
#define DEM_H #define DEM_H
#include <QString>
#include <QMap> #include <QMap>
#include <QByteArray> #include <QByteArray>
#include <QDir>
class QDir; class QString;
class Coordinates; class Coordinates;
class DEM class DEM
{ {
public: public:
DEM() {} static void setDir(const QString &path);
DEM(const QString &dir) : _dir(dir) {} static qreal elevation(const Coordinates &c);
qreal elevation(const Coordinates &c);
private: private:
struct Key { struct Key {
@ -31,13 +30,12 @@ private:
else else
return (lat < other.lat); return (lat < other.lat);
} }
}; };
QString fileName(const Key &key) const; static QString fileName(const Key &key);
QString _dir; static QString _dir;
QMap<Key, QByteArray> _data; static QMap<Key, QByteArray> _data;
}; };
#endif // DEM_H #endif // DEM_H

View File

@ -1,12 +1,17 @@
#include "dem.h"
#include "route.h" #include "route.h"
bool Route::_useDEMElevation = false;
Route::Route(const RouteData &data) : _data(data) Route::Route(const RouteData &data) : _data(data)
{ {
qreal dist = 0; qreal dist = 0;
_distance.append(dist); _distance.append(0);
for (int i = 1; i < data.count(); i++) {
dist += data.at(i).coordinates().distanceTo(data.at(i-1).coordinates()); for (int i = 1; i < _data.count(); i++) {
dist += _data.at(i).coordinates().distanceTo(_data.at(i-1).coordinates());
_distance.append(dist); _distance.append(dist);
} }
} }
@ -25,10 +30,19 @@ Graph Route::elevation() const
{ {
Graph graph; Graph graph;
for (int i = 0; i < _data.size(); i++) for (int i = 0; i < _data.size(); i++) {
if (_data.at(i).hasElevation()) if (_data.at(i).hasElevation() && !_useDEMElevation)
graph.append(GraphPoint(_distance.at(i), NAN, graph.append(GraphPoint(_distance.at(i), NAN,
_data.at(i).elevation())); _data.at(i).elevation()));
else {
qreal elevation = DEM::elevation(_data.at(i).coordinates());
if (!std::isnan(elevation))
graph.append(GraphPoint(_distance.at(i), NAN, elevation));
else if (_data.at(i).hasElevation())
graph.append(GraphPoint(_distance.at(i), NAN,
_data.at(i).elevation()));
}
}
return graph; return graph;
} }

View File

@ -24,9 +24,13 @@ public:
bool isNull() const {return (_data.count() < 2);} bool isNull() const {return (_data.count() < 2);}
static void useDEMElevation(bool use) {_useDEMElevation = use;}
private: private:
const RouteData &_data; const RouteData &_data;
QVector<qreal> _distance; QVector<qreal> _distance;
static bool _useDEMElevation;
}; };
#endif // ROUTE_H #endif // ROUTE_H

View File

@ -15,8 +15,6 @@ bool Track::_outlierEliminate = true;
bool Track::_useReportedSpeed = false; bool Track::_useReportedSpeed = false;
bool Track::_useDEMElevation = false; bool Track::_useDEMElevation = false;
DEM Track::_dem;
static qreal median(QVector<qreal> &v) static qreal median(QVector<qreal> &v)
{ {
@ -160,7 +158,7 @@ Graph Track::elevation() const
raw.append(GraphPoint(_distance.at(i), _time.at(i), raw.append(GraphPoint(_distance.at(i), _time.at(i),
_data.at(i).elevation())); _data.at(i).elevation()));
else { else {
qreal elevation = _dem.elevation(_data.at(i).coordinates()); qreal elevation = DEM::elevation(_data.at(i).coordinates());
if (!std::isnan(elevation)) if (!std::isnan(elevation))
raw.append(GraphPoint(_distance.at(i), _time.at(i), elevation)); raw.append(GraphPoint(_distance.at(i), _time.at(i), elevation));
else if (_data.at(i).hasElevation()) else if (_data.at(i).hasElevation())

View File

@ -7,7 +7,6 @@
#include <QDir> #include <QDir>
#include "trackdata.h" #include "trackdata.h"
#include "graph.h" #include "graph.h"
#include "dem.h"
#include "path.h" #include "path.h"
@ -47,7 +46,6 @@ public:
{_outlierEliminate = eliminate;} {_outlierEliminate = eliminate;}
static void useReportedSpeed(bool use) {_useReportedSpeed = use;} static void useReportedSpeed(bool use) {_useReportedSpeed = use;}
static void useDEMElevation(bool use) {_useDEMElevation = use;} static void useDEMElevation(bool use) {_useDEMElevation = use;}
static void setDEMDir(const QString &path) {_dem = DEM(path);}
private: private:
bool discardStopPoint(int i) const; bool discardStopPoint(int i) const;
@ -73,7 +71,6 @@ private:
static int _pauseInterval; static int _pauseInterval;
static bool _useReportedSpeed; static bool _useReportedSpeed;
static bool _useDEMElevation; static bool _useDEMElevation;
static DEM _dem;
}; };
#endif // TRACK_H #endif // TRACK_H