mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 11:45:53 +01:00
Enable DEM elevation for all data types (waypoints, routes)
This commit is contained in:
parent
b8a2b76d7c
commit
bd4af8c7e5
@ -12,7 +12,7 @@
|
||||
#include "map/ellipsoid.h"
|
||||
#include "map/gcs.h"
|
||||
#include "map/pcs.h"
|
||||
#include "data/track.h"
|
||||
#include "data/dem.h"
|
||||
#include "opengl.h"
|
||||
#include "gui.h"
|
||||
#include "settings.h"
|
||||
@ -65,8 +65,7 @@ App::App(int &argc, char **argv) : QApplication(argc, argv)
|
||||
OPENGL_SET_SAMPLES(4);
|
||||
loadDatums();
|
||||
loadPCSs();
|
||||
|
||||
Track::setDEMDir(ProgramPaths::demDir());
|
||||
DEM::setDir(ProgramPaths::demDir());
|
||||
|
||||
_gui = new GUI();
|
||||
}
|
||||
|
@ -875,6 +875,11 @@ void GUI::openOptions()
|
||||
Track::action(options.option); \
|
||||
reload = true; \
|
||||
}
|
||||
#define SET_DATA_OPTION(option, action) \
|
||||
if (options.option != _options.option) { \
|
||||
Data::action(options.option); \
|
||||
reload = true; \
|
||||
}
|
||||
|
||||
Options options(_options);
|
||||
bool reload = false;
|
||||
@ -913,7 +918,7 @@ void GUI::openOptions()
|
||||
SET_TRACK_OPTION(pauseSpeed, setPauseSpeed);
|
||||
SET_TRACK_OPTION(pauseInterval, setPauseInterval);
|
||||
SET_TRACK_OPTION(useReportedSpeed, useReportedSpeed);
|
||||
SET_TRACK_OPTION(useDEMElevation, useDEMElevation);
|
||||
SET_DATA_OPTION(useDEMElevation, useDEMElevation);
|
||||
|
||||
if (options.poiRadius != _options.poiRadius)
|
||||
_poi->setRadius(options.poiRadius);
|
||||
@ -2077,7 +2082,7 @@ void GUI::readSettings()
|
||||
Track::setPauseSpeed(_options.pauseSpeed);
|
||||
Track::setPauseInterval(_options.pauseInterval);
|
||||
Track::useReportedSpeed(_options.useReportedSpeed);
|
||||
Track::useDEMElevation(_options.useDEMElevation);
|
||||
Data::useDEMElevation(_options.useDEMElevation);
|
||||
|
||||
_poi->setRadius(_options.poiRadius);
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "oziparsers.h"
|
||||
#include "locparser.h"
|
||||
#include "slfparser.h"
|
||||
#include "dem.h"
|
||||
#include "data.h"
|
||||
|
||||
|
||||
@ -49,6 +50,7 @@ static QHash<QString, Parser*> parsers()
|
||||
|
||||
|
||||
QHash<QString, Parser*> Data::_parsers = parsers();
|
||||
bool Data::_useDEMElevation = false;
|
||||
|
||||
Data::~Data()
|
||||
{
|
||||
@ -64,6 +66,13 @@ void Data::processData()
|
||||
_tracks.append(new Track(_trackData.at(i)));
|
||||
for (int i = 0; i < _routeData.count(); 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)
|
||||
@ -134,3 +143,10 @@ QStringList Data::filter()
|
||||
|
||||
return filter;
|
||||
}
|
||||
|
||||
void Data::useDEMElevation(bool use)
|
||||
{
|
||||
_useDEMElevation = use;
|
||||
Route::useDEMElevation(use);
|
||||
Track::useDEMElevation(use);
|
||||
}
|
||||
|
@ -32,6 +32,8 @@ public:
|
||||
static QString formats();
|
||||
static QStringList filter();
|
||||
|
||||
static void useDEMElevation(bool use);
|
||||
|
||||
private:
|
||||
void processData();
|
||||
|
||||
@ -46,6 +48,7 @@ private:
|
||||
QList<RouteData> _routeData;
|
||||
|
||||
static QHash<QString, Parser*> _parsers;
|
||||
static bool _useDEMElevation;
|
||||
};
|
||||
|
||||
#endif // DATA_H
|
||||
|
@ -1,4 +1,6 @@
|
||||
#include <QtEndian>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include "common/coordinates.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);
|
||||
}
|
||||
|
||||
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 ew = (key.lon >= 0) ? 'E' : 'W';
|
||||
@ -59,6 +65,11 @@ QString DEM::fileName(const Key &key) const
|
||||
return QDir(_dir).absoluteFilePath(basename);
|
||||
}
|
||||
|
||||
void DEM::setDir(const QString &path)
|
||||
{
|
||||
_dir = path;
|
||||
}
|
||||
|
||||
qreal DEM::elevation(const Coordinates &c)
|
||||
{
|
||||
if (_dir.isEmpty())
|
||||
|
@ -1,19 +1,18 @@
|
||||
#ifndef DEM_H
|
||||
#define DEM_H
|
||||
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
#include <QByteArray>
|
||||
#include <QDir>
|
||||
|
||||
class QDir;
|
||||
class QString;
|
||||
class Coordinates;
|
||||
|
||||
class DEM
|
||||
{
|
||||
public:
|
||||
DEM() {}
|
||||
DEM(const QString &dir) : _dir(dir) {}
|
||||
qreal elevation(const Coordinates &c);
|
||||
static void setDir(const QString &path);
|
||||
static qreal elevation(const Coordinates &c);
|
||||
|
||||
private:
|
||||
struct Key {
|
||||
@ -31,13 +30,12 @@ private:
|
||||
else
|
||||
return (lat < other.lat);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
QString fileName(const Key &key) const;
|
||||
static QString fileName(const Key &key);
|
||||
|
||||
QString _dir;
|
||||
QMap<Key, QByteArray> _data;
|
||||
static QString _dir;
|
||||
static QMap<Key, QByteArray> _data;
|
||||
};
|
||||
|
||||
#endif // DEM_H
|
||||
|
@ -1,12 +1,17 @@
|
||||
#include "dem.h"
|
||||
#include "route.h"
|
||||
|
||||
|
||||
bool Route::_useDEMElevation = false;
|
||||
|
||||
Route::Route(const RouteData &data) : _data(data)
|
||||
{
|
||||
qreal dist = 0;
|
||||
|
||||
_distance.append(dist);
|
||||
for (int i = 1; i < data.count(); i++) {
|
||||
dist += data.at(i).coordinates().distanceTo(data.at(i-1).coordinates());
|
||||
_distance.append(0);
|
||||
|
||||
for (int i = 1; i < _data.count(); i++) {
|
||||
dist += _data.at(i).coordinates().distanceTo(_data.at(i-1).coordinates());
|
||||
_distance.append(dist);
|
||||
}
|
||||
}
|
||||
@ -25,10 +30,19 @@ Graph Route::elevation() const
|
||||
{
|
||||
Graph graph;
|
||||
|
||||
for (int i = 0; i < _data.size(); i++)
|
||||
if (_data.at(i).hasElevation())
|
||||
for (int i = 0; i < _data.size(); i++) {
|
||||
if (_data.at(i).hasElevation() && !_useDEMElevation)
|
||||
graph.append(GraphPoint(_distance.at(i), NAN,
|
||||
_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;
|
||||
}
|
||||
|
@ -24,9 +24,13 @@ public:
|
||||
|
||||
bool isNull() const {return (_data.count() < 2);}
|
||||
|
||||
static void useDEMElevation(bool use) {_useDEMElevation = use;}
|
||||
|
||||
private:
|
||||
const RouteData &_data;
|
||||
QVector<qreal> _distance;
|
||||
|
||||
static bool _useDEMElevation;
|
||||
};
|
||||
|
||||
#endif // ROUTE_H
|
||||
|
@ -15,8 +15,6 @@ bool Track::_outlierEliminate = true;
|
||||
bool Track::_useReportedSpeed = false;
|
||||
bool Track::_useDEMElevation = false;
|
||||
|
||||
DEM Track::_dem;
|
||||
|
||||
|
||||
static qreal median(QVector<qreal> &v)
|
||||
{
|
||||
@ -160,7 +158,7 @@ Graph Track::elevation() const
|
||||
raw.append(GraphPoint(_distance.at(i), _time.at(i),
|
||||
_data.at(i).elevation()));
|
||||
else {
|
||||
qreal elevation = _dem.elevation(_data.at(i).coordinates());
|
||||
qreal elevation = DEM::elevation(_data.at(i).coordinates());
|
||||
if (!std::isnan(elevation))
|
||||
raw.append(GraphPoint(_distance.at(i), _time.at(i), elevation));
|
||||
else if (_data.at(i).hasElevation())
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <QDir>
|
||||
#include "trackdata.h"
|
||||
#include "graph.h"
|
||||
#include "dem.h"
|
||||
#include "path.h"
|
||||
|
||||
|
||||
@ -47,7 +46,6 @@ public:
|
||||
{_outlierEliminate = eliminate;}
|
||||
static void useReportedSpeed(bool use) {_useReportedSpeed = use;}
|
||||
static void useDEMElevation(bool use) {_useDEMElevation = use;}
|
||||
static void setDEMDir(const QString &path) {_dem = DEM(path);}
|
||||
|
||||
private:
|
||||
bool discardStopPoint(int i) const;
|
||||
@ -73,7 +71,6 @@ private:
|
||||
static int _pauseInterval;
|
||||
static bool _useReportedSpeed;
|
||||
static bool _useDEMElevation;
|
||||
static DEM _dem;
|
||||
};
|
||||
|
||||
#endif // TRACK_H
|
||||
|
Loading…
Reference in New Issue
Block a user