2020-03-25 23:08:26 +01:00
|
|
|
#include "dem.h"
|
2016-08-09 01:16:19 +02:00
|
|
|
#include "route.h"
|
|
|
|
|
2020-03-25 23:08:26 +01:00
|
|
|
bool Route::_useDEM = false;
|
|
|
|
bool Route::_show2ndElevation = false;
|
2019-01-17 00:47:44 +01:00
|
|
|
|
2016-10-28 14:33:36 +02:00
|
|
|
Route::Route(const RouteData &data) : _data(data)
|
2016-08-09 01:16:19 +02:00
|
|
|
{
|
|
|
|
qreal dist = 0;
|
|
|
|
|
2019-01-17 00:47:44 +01:00
|
|
|
_distance.append(0);
|
|
|
|
|
|
|
|
for (int i = 1; i < _data.count(); i++) {
|
|
|
|
dist += _data.at(i).coordinates().distanceTo(_data.at(i-1).coordinates());
|
2016-09-19 23:35:04 +02:00
|
|
|
_distance.append(dist);
|
2016-08-09 01:16:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
Path Route::path() const
|
|
|
|
{
|
|
|
|
Path ret;
|
2019-02-11 23:28:08 +01:00
|
|
|
ret.append(PathSegment());
|
|
|
|
PathSegment &ps = ret.last();
|
2017-03-18 01:30:31 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < _data.size(); i++)
|
2019-02-11 23:28:08 +01:00
|
|
|
ps.append(PathPoint(_data.at(i).coordinates(), _distance.at(i)));
|
2017-03-18 01:30:31 +01:00
|
|
|
|
2022-09-25 02:15:24 +02:00
|
|
|
ret.setStyle(_data.style());
|
|
|
|
|
2017-03-18 01:30:31 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-03-25 23:08:26 +01:00
|
|
|
Graph Route::gpsElevation() const
|
2016-08-09 01:16:19 +02:00
|
|
|
{
|
2016-09-19 00:56:10 +02:00
|
|
|
Graph graph;
|
2023-05-04 21:49:02 +02:00
|
|
|
graph.append(GraphSegment(QDateTime()));
|
2019-02-11 23:28:08 +01:00
|
|
|
GraphSegment &gs = graph.last();
|
2016-08-09 01:16:19 +02:00
|
|
|
|
2019-08-29 20:15:03 +02:00
|
|
|
for (int i = 0; i < _data.size(); i++)
|
2019-09-29 00:03:14 +02:00
|
|
|
if (_data.at(i).hasElevation())
|
|
|
|
gs.append(GraphPoint(_distance.at(i), NAN, _data.at(i).elevation()));
|
2016-08-09 23:08:49 +02:00
|
|
|
|
2022-09-23 02:34:18 +02:00
|
|
|
if (_data.style().color().isValid())
|
|
|
|
graph.setColor(_data.style().color());
|
|
|
|
|
2016-08-09 23:08:49 +02:00
|
|
|
return graph;
|
|
|
|
}
|
|
|
|
|
2020-03-25 23:08:26 +01:00
|
|
|
Graph Route::demElevation() const
|
|
|
|
{
|
|
|
|
Graph graph;
|
2023-05-04 21:49:02 +02:00
|
|
|
graph.append(GraphSegment(QDateTime()));
|
2020-03-25 23:08:26 +01:00
|
|
|
GraphSegment &gs = graph.last();
|
|
|
|
|
|
|
|
for (int i = 0; i < _data.size(); i++) {
|
|
|
|
qreal dem = DEM::elevation(_data.at(i).coordinates());
|
|
|
|
if (!std::isnan(dem))
|
|
|
|
gs.append(GraphPoint(_distance.at(i), NAN, dem));
|
|
|
|
}
|
|
|
|
|
2022-09-23 02:34:18 +02:00
|
|
|
if (_data.style().color().isValid())
|
|
|
|
graph.setColor(_data.style().color());
|
|
|
|
|
2020-03-25 23:08:26 +01:00
|
|
|
return graph;
|
|
|
|
}
|
|
|
|
|
|
|
|
GraphPair Route::elevation() const
|
|
|
|
{
|
|
|
|
if (_useDEM) {
|
|
|
|
Graph dem(demElevation());
|
2023-04-10 13:06:19 +02:00
|
|
|
return (dem.isEmpty())
|
|
|
|
? GraphPair(gpsElevation(), Graph())
|
|
|
|
: GraphPair(dem, _show2ndElevation ? gpsElevation() : Graph());
|
2020-03-25 23:08:26 +01:00
|
|
|
} else {
|
|
|
|
Graph gps(gpsElevation());
|
2023-04-10 13:06:19 +02:00
|
|
|
return (gps.isEmpty())
|
2023-04-10 17:21:02 +02:00
|
|
|
? GraphPair(demElevation(), Graph())
|
|
|
|
: GraphPair(gps, _show2ndElevation ? demElevation() : Graph());
|
2020-03-25 23:08:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-09 23:08:49 +02:00
|
|
|
qreal Route::distance() const
|
|
|
|
{
|
2016-09-19 23:35:04 +02:00
|
|
|
return (_distance.isEmpty()) ? 0 : _distance.last();
|
2016-08-09 01:16:19 +02:00
|
|
|
}
|