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

91 lines
1.9 KiB
C++
Raw Normal View History

#include <QFile>
2018-01-08 23:47:45 +01:00
#include <QDebug>
#include "common/wgs84.h"
#include "ellipsoid.h"
QMap<int, Ellipsoid> Ellipsoid::_ellipsoids = defaults();
const Ellipsoid &Ellipsoid::WGS84()
{
static Ellipsoid e(WGS84_RADIUS, WGS84_FLATTENING);
return e;
}
QMap<int, Ellipsoid> Ellipsoid::defaults()
{
QMap<int, Ellipsoid> map;
map.insert(7030, WGS84());
return map;
}
const Ellipsoid *Ellipsoid::ellipsoid(int id)
{
2018-03-29 00:29:08 +02:00
QMap<int, Ellipsoid>::const_iterator it(_ellipsoids.find(id));
2018-03-29 00:29:08 +02:00
if (it == _ellipsoids.constEnd())
return 0;
2018-01-08 23:47:45 +01:00
else
return &(it.value());
2018-01-09 23:19:35 +01:00
}
void Ellipsoid::loadList(const QString &path)
{
QFile file(path);
bool res;
int ln = 0;
2018-01-08 23:47:45 +01:00
if (!file.open(QFile::ReadOnly)) {
qWarning("Error opening ellipsoids file: %s: %s", qPrintable(path),
qPrintable(file.errorString()));
return;
}
while (!file.atEnd()) {
ln++;
QByteArray line = file.readLine();
QList<QByteArray> list = line.split(',');
if (list.size() != 4) {
qWarning("%s: %d: Format error", qPrintable(path), ln);
continue;
}
2018-01-08 23:47:45 +01:00
int id = list[1].trimmed().toInt(&res);
if (!res) {
qWarning("%s: %d: Invalid ellipsoid code", qPrintable(path), ln);
continue;
}
double radius = list[2].trimmed().toDouble(&res);
if (!res) {
qWarning("%s: %d: Invalid radius", qPrintable(path), ln);
continue;
}
double flattening = list[3].trimmed().toDouble(&res);
if (!res) {
qWarning("%s: %d: Invalid flattening", qPrintable(path), ln);
continue;
}
Ellipsoid e(radius, 1.0/flattening);
_ellipsoids.insert(id, e);
}
}
2018-01-08 23:47:45 +01:00
Ellipsoid::Ellipsoid(double radius, double flattening)
: _radius(radius), _flattening(flattening)
{
_es = 2.0 * flattening - flattening * flattening;
2018-05-18 22:10:43 +02:00
_e2s = (1.0 / (1.0 - _es)) - 1.0;
_b = radius * (1.0 - flattening);
}
#ifndef QT_NO_DEBUG
2018-01-08 23:47:45 +01:00
QDebug operator<<(QDebug dbg, const Ellipsoid &ellipsoid)
{
dbg.nospace() << "Ellipsoid(" << ellipsoid.radius() << ", "
<< 1.0 / ellipsoid.flattening() << ")";
2018-01-21 11:19:46 +01:00
return dbg.space();
2018-01-08 23:47:45 +01:00
}
#endif // QT_NO_DEBUG