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

Fixed broken projection comparsion

+ refactoring/code cleanup
This commit is contained in:
Martin Tůma 2020-11-28 14:48:20 +01:00
parent 96733883cb
commit 0cc6908b30
2 changed files with 32 additions and 35 deletions

View File

@ -94,9 +94,9 @@ static QList<QByteArray> split(const QByteArray &line)
return list; return list;
} }
static QMap<QString, QString> kvMap(const QByteArray &line) static QMap<QByteArray, QByteArray> kvMap(const QByteArray &line)
{ {
QMap<QString, QString> map; QMap<QByteArray, QByteArray> map;
QList<QByteArray> parts(split(line)); QList<QByteArray> parts(split(line));
for (int i = 0; i < parts.size(); i++) { for (int i = 0; i < parts.size(); i++) {
@ -111,7 +111,7 @@ static QMap<QString, QString> kvMap(const QByteArray &line)
static double parameter(const QString &str, bool *res) static double parameter(const QString &str, bool *res)
{ {
if (str.isEmpty() || str == "NOT_APPLICABLE") { if (str.isEmpty() || str == "NOT_APPLICABLE" || str == "UNKNOWN") {
*res = true; *res = true;
return NAN; return NAN;
} }
@ -122,15 +122,15 @@ static double parameter(const QString &str, bool *res)
bool BSBMap::parseBSB(const QByteArray &line) bool BSBMap::parseBSB(const QByteArray &line)
{ {
QMap<QString, QString> map(kvMap(line)); QMap<QByteArray, QByteArray> map(kvMap(line));
_name = map.value("NA"); _name = QString::fromLatin1(map.value("NA"));
if (_name.isEmpty()) { if (_name.isEmpty()) {
_errorString = "Invalid/missing BSB NA field"; _errorString = "Invalid/missing BSB NA field";
return false; return false;
} }
QStringList sv(map.value("RA").split(',')); QList<QByteArray> sv(map.value("RA").split(','));
unsigned w, h; unsigned w, h;
bool wok = false, hok = false; bool wok = false, hok = false;
if (sv.size() == 2) { if (sv.size() == 2) {
@ -154,7 +154,7 @@ bool BSBMap::parseBSB(const QByteArray &line)
bool BSBMap::parseKNP(const QByteArray &line, QString &datum, QString &proj, bool BSBMap::parseKNP(const QByteArray &line, QString &datum, QString &proj,
double &pp) double &pp)
{ {
QMap<QString, QString> map(kvMap(line)); QMap<QByteArray, QByteArray> map(kvMap(line));
bool ok; bool ok;
if (!(map.contains("PR") && map.contains("GD") && map.contains("PP"))) { if (!(map.contains("PR") && map.contains("GD") && map.contains("PP"))) {
@ -174,20 +174,17 @@ bool BSBMap::parseKNP(const QByteArray &line, QString &datum, QString &proj,
return true; return true;
} }
bool BSBMap::parseKNQ(const QByteArray &line, double &p2, double &p3) bool BSBMap::parseKNQ(const QByteArray &line, double params[9])
{ {
QMap<QString, QString> map(kvMap(line)); QMap<QByteArray, QByteArray> map(kvMap(line));
bool ok; bool ok;
p2 = parameter(map.value("P2"), &ok); for (int i = 1; i <= 8; i++) {
if (!ok) { params[i] = parameter(map.value(QString("P%1").arg(i).toLatin1()), &ok);
_errorString = "Invalid KNQ P2 parameter"; if (!ok) {
return false; _errorString = QString("Invalid KNQ P%1 parameter").arg(i);
} return false;
p3 = parameter(map.value("P3"), &ok); }
if (!ok) {
_errorString = "Invalid KNQ P3 parameter";
return false;
} }
return true; return true;
@ -232,7 +229,7 @@ bool BSBMap::readHeader(QFile &file, bool mangled)
{ {
QByteArray line; QByteArray line;
QString datum, proj; QString datum, proj;
double pp, p2, p3; double params[9];
QList<ReferencePoint> points; QList<ReferencePoint> points;
while (readHeaderLine(file, mangled, line)) { while (readHeaderLine(file, mangled, line)) {
@ -247,14 +244,14 @@ bool BSBMap::readHeader(QFile &file, bool mangled)
if ((isType(line, "BSB/") || isType(line, "NOS/")) if ((isType(line, "BSB/") || isType(line, "NOS/"))
&& !parseBSB(hdrData(line))) && !parseBSB(hdrData(line)))
return false; return false;
else if (isType(line, "KNP/") && !parseKNP(hdrData(line), datum, proj, else if (isType(line, "KNP/")
pp)) && !parseKNP(hdrData(line), datum, proj, params[0]))
return false; return false;
else if (isType(line, "KNQ/") && !parseKNQ(hdrData(line), p2, p3)) else if (isType(line, "KNQ/") && !parseKNQ(hdrData(line), params))
return false; return false;
else if (isType(line, "REF/")) { else if (isType(line, "REF/")) {
if (_projection.isNull()) { if (_projection.isNull()) {
if (!createProjection(datum, proj, pp, p2, p3)) if (!createProjection(datum, proj, params))
return false; return false;
} }
if (!parseREF(hdrData(line), points)) if (!parseREF(hdrData(line), points))
@ -282,7 +279,7 @@ bool BSBMap::createTransform(const QList<ReferencePoint> &points)
} }
bool BSBMap::createProjection(const QString &datum, const QString &proj, bool BSBMap::createProjection(const QString &datum, const QString &proj,
double pp, double p2, double p3) double params[9])
{ {
const GCS *gcs = 0; const GCS *gcs = 0;
PCS pcs; PCS pcs;
@ -296,18 +293,18 @@ bool BSBMap::createProjection(const QString &datum, const QString &proj,
return false; return false;
} }
if (proj.compare("MERCATOR", Qt::CaseInsensitive)) { if (!proj.compare("MERCATOR", Qt::CaseInsensitive)) {
Projection::Setup setup(0, 0, 1, 0, 0, 0, 0); Projection::Setup setup(0, 0, NAN, 0, 0, NAN, NAN);
pcs = PCS(gcs, 9804, setup, 9001); pcs = PCS(gcs, 1024, setup, 9001);
} else if (proj.compare("TRANSVERSE MERCATOR", Qt::CaseInsensitive)) { } else if (!proj.compare("TRANSVERSE MERCATOR", Qt::CaseInsensitive)) {
Projection::Setup setup(0, pp, 1, 0, 0, 0, 0); Projection::Setup setup(0, params[1], params[2], 0, 0, NAN, NAN);
pcs = PCS(gcs, 9807, setup, 9001); pcs = PCS(gcs, 9807, setup, 9001);
} else if (proj.compare("UNIVERSAL TRANSVERSE MERCATOR", } else if (!proj.compare("UNIVERSAL TRANSVERSE MERCATOR",
Qt::CaseInsensitive)) { Qt::CaseInsensitive)) {
Projection::Setup setup(0, pp, 0.9996, 500000, 0, 0, 0); Projection::Setup setup(0, params[0], 0.9996, 500000, 0, NAN, NAN);
pcs = PCS(gcs, 9807, setup, 9001); pcs = PCS(gcs, 9807, setup, 9001);
} else if (proj.compare("LAMBERT CONFORMAL CONIC", Qt::CaseInsensitive)) { } else if (!proj.compare("LAMBERT CONFORMAL CONIC", Qt::CaseInsensitive)) {
Projection::Setup setup(0, pp, 1, 0, 0, p2, p3); Projection::Setup setup(0, params[0], NAN, 0, 0, params[2], params[3]);
pcs = PCS(gcs, 9802, setup, 9001); pcs = PCS(gcs, 9802, setup, 9001);
} else { } else {
_errorString = proj + ": Unknown/missing projection"; _errorString = proj + ": Unknown/missing projection";

View File

@ -36,12 +36,12 @@ private:
bool parseBSB(const QByteArray &line); bool parseBSB(const QByteArray &line);
bool parseKNP(const QByteArray &line, QString &datum, QString &proj, bool parseKNP(const QByteArray &line, QString &datum, QString &proj,
double &pp); double &pp);
bool parseKNQ(const QByteArray &line, double &p2, double &p3); bool parseKNQ(const QByteArray &line, double params[9]);
bool parseREF(const QByteArray &line, QList<ReferencePoint> &points); bool parseREF(const QByteArray &line, QList<ReferencePoint> &points);
bool parseRGB(const QByteArray &line); bool parseRGB(const QByteArray &line);
bool readHeader(QFile &file, bool mangled); bool readHeader(QFile &file, bool mangled);
bool createProjection(const QString &datum, const QString &proj, bool createProjection(const QString &datum, const QString &proj,
double pp, double p2, double p3); double params[9]);
bool createTransform(const QList<ReferencePoint> &points); bool createTransform(const QList<ReferencePoint> &points);
QImage readImage(); QImage readImage();
bool readRow(QFile &file, char bits, uchar *buf); bool readRow(QFile &file, char bits, uchar *buf);