1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-02-17 16:20:48 +01:00

Fixed broken DEM value reading on southern and western coordinates

Fixes #240
This commit is contained in:
Martin Tůma 2019-10-31 17:47:58 +01:00
parent 315c095af9
commit 2f2f155707

View File

@ -1,4 +1,9 @@
#include <QtEndian>
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QtCore/qmath.h>
#else // QT5
#include <QtMath>
#endif // QT5
#include <QDir>
#include <QFile>
#include "common/coordinates.h"
@ -37,10 +42,10 @@ static qreal height(const Coordinates &c, const QByteArray *data)
else
return NAN;
int row = (int)((c.lat() - (int)c.lat()) * (samples - 1));
int col = (int)((c.lon() - (int)c.lon()) * (samples - 1));
qreal dx = ((c.lon() - (int)c.lon()) * (samples - 1)) - col;
qreal dy = ((c.lat() - (int)c.lat()) * (samples - 1)) - row;
int row = (int)((c.lat() - qFloor(c.lat())) * (samples - 1));
int col = (int)((c.lon() - qFloor(c.lon())) * (samples - 1));
qreal dx = ((c.lon() - qFloor(c.lon())) * (samples - 1)) - col;
qreal dy = ((c.lat() - qFloor(c.lat())) * (samples - 1)) - row;
qreal p0 = value(col, row, samples, data);
qreal p1 = value(col + 1, row, samples, data);
@ -75,7 +80,7 @@ qreal DEM::elevation(const Coordinates &c)
if (_dir.isEmpty())
return NAN;
Key k((int)c.lon(), (int)c.lat());
Key k(qFloor(c.lon()), qFloor(c.lat()));
QByteArray *ba = _data[k];
if (!ba) {