1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 13:41:16 +01:00
GPXSee/src/data/route.cpp

58 lines
1.2 KiB
C++
Raw Normal View History

#include "dem.h"
2016-08-09 01:16:19 +02:00
#include "route.h"
bool Route::_useDEM = false;
Route::Route(const RouteData &data) : _data(data)
2016-08-09 01:16:19 +02:00
{
qreal dist = 0;
_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
}
}
Path Route::path() const
{
Path ret;
2019-02-11 23:28:08 +01:00
ret.append(PathSegment());
PathSegment &ps = ret.last();
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)));
return ret;
}
2016-09-19 00:56:10 +02:00
Graph Route::elevation() const
2016-08-09 01:16:19 +02:00
{
2016-09-19 00:56:10 +02:00
Graph graph;
2019-02-11 23:28:08 +01:00
graph.append(GraphSegment());
GraphSegment &gs = graph.last();
2016-08-09 01:16:19 +02:00
for (int i = 0; i < _data.size(); i++) {
if (_data.at(i).hasElevation() && !_useDEM)
2019-02-11 23:28:08 +01:00
gs.append(GraphPoint(_distance.at(i), NAN,
_data.at(i).elevation()));
else {
qreal elevation = DEM::elevation(_data.at(i).coordinates());
if (!std::isnan(elevation))
2019-02-11 23:28:08 +01:00
gs.append(GraphPoint(_distance.at(i), NAN, elevation));
else if (_data.at(i).hasElevation())
2019-02-11 23:28:08 +01:00
gs.append(GraphPoint(_distance.at(i), NAN,
_data.at(i).elevation()));
}
}
return graph;
}
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
}