1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Fixed issue with Mercator projections

This commit is contained in:
Martin Tůma 2020-12-02 20:51:19 +01:00
parent af6082425e
commit 8d52dbf59f
2 changed files with 27 additions and 21 deletions

View File

@ -182,20 +182,28 @@ bool BSBMap::parseKNQ(const QByteArray &line, double params[9])
return true; return true;
} }
bool BSBMap::parseREF(const QByteArray &line, QList<ReferencePoint> &points) bool BSBMap::parseREF(const QByteArray &line, const QString &datum,
const QString &proj, double params[9], QList<ReferencePoint> &points)
{ {
QList<QByteArray> fields(line.split(',')); QList<QByteArray> fields(line.split(','));
if (fields.size() == 5) { if (fields.size() == 5) {
bool xok, yok, lonok, latok; bool xok, yok, lonok, latok;
Coordinates c(fields.at(4).toDouble(&lonok),
fields.at(3).toDouble(&latok));
if (lonok && latok && c.isValid()) {
if (_projection.isNull()) {
if (!createProjection(datum, proj, params, c))
return false;
}
CalibrationPoint p(PointD(fields.at(1).toDouble(&xok), CalibrationPoint p(PointD(fields.at(1).toDouble(&xok),
fields.at(2).toDouble(&yok)), Coordinates(fields.at(4).toDouble(&lonok), fields.at(2).toDouble(&yok)), c);
fields.at(3).toDouble(&latok))); if (xok && yok) {
if (xok && yok && lonok && latok) {
points.append(p.rp(_projection)); points.append(p.rp(_projection));
return true; return true;
} }
} }
}
_errorString = QString(line) + ": Invalid reference point entry"; _errorString = QString(line) + ": Invalid reference point entry";
return false; return false;
@ -207,9 +215,10 @@ bool BSBMap::parseRGB(const QByteArray &line)
bool iok, rok, gok, bok; bool iok, rok, gok, bok;
int i = fields.at(0).toUInt(&iok); int i = fields.at(0).toUInt(&iok);
if (fields.size() == 4 && i > 0 && i < 256) { if (iok && fields.size() == 4 && i > 0 && i < 256) {
_palette[i-1] = Color::rgb(fields.at(1).toUInt(&rok), _palette[i-1] = Color::rgb(fields.at(1).toUInt(&rok),
fields.at(2).toUInt(&gok), fields.at(3).toUInt(&bok)); fields.at(2).toUInt(&gok), fields.at(3).toUInt(&bok));
if (rok && gok && bok)
return true; return true;
} }
@ -240,14 +249,10 @@ bool BSBMap::readHeader(QFile &file)
return false; return false;
else if (isType(line, "KNQ/") && !parseKNQ(hdrData(line), params)) 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()) { && !parseREF(hdrData(line), datum, proj, params, points))
if (!createProjection(datum, proj, params))
return false; return false;
} else if (isType(line, "RGB/") && !parseRGB(hdrData(line)))
if (!parseREF(hdrData(line), points))
return false;
} else if (isType(line, "RGB/") && !parseRGB(hdrData(line)))
return false; return false;
line.clear(); line.clear();
@ -283,7 +288,7 @@ bool BSBMap::createTransform(QList<ReferencePoint> &points)
} }
bool BSBMap::createProjection(const QString &datum, const QString &proj, bool BSBMap::createProjection(const QString &datum, const QString &proj,
double params[9]) double params[9], const Coordinates &c)
{ {
const GCS *gcs = 0; const GCS *gcs = 0;
PCS pcs; PCS pcs;
@ -298,7 +303,7 @@ bool BSBMap::createProjection(const QString &datum, const QString &proj,
} }
if (!proj.compare("MERCATOR", Qt::CaseInsensitive)) { if (!proj.compare("MERCATOR", Qt::CaseInsensitive)) {
Projection::Setup setup(0, 0, NAN, 0, 0, NAN, NAN); Projection::Setup setup(0, c.lon(), NAN, 0, 0, NAN, NAN);
pcs = PCS(gcs, 9804, setup, 9001); pcs = PCS(gcs, 9804, setup, 9001);
} else if (!proj.compare("TRANSVERSE MERCATOR", Qt::CaseInsensitive)) { } else if (!proj.compare("TRANSVERSE MERCATOR", Qt::CaseInsensitive)) {
Projection::Setup setup(0, params[1], params[2], 0, 0, NAN, NAN); Projection::Setup setup(0, params[1], params[2], 0, 0, NAN, NAN);

View File

@ -37,11 +37,12 @@ private:
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 params[9]); bool parseKNQ(const QByteArray &line, double params[9]);
bool parseREF(const QByteArray &line, QList<ReferencePoint> &points); bool parseREF(const QByteArray &line, const QString &datum,
const QString &proj, double params[9], QList<ReferencePoint> &points);
bool parseRGB(const QByteArray &line); bool parseRGB(const QByteArray &line);
bool readHeader(QFile &file); bool readHeader(QFile &file);
bool createProjection(const QString &datum, const QString &proj, bool createProjection(const QString &datum, const QString &proj,
double params[9]); double params[9], const Coordinates &c);
bool createTransform(QList<ReferencePoint> &points); bool createTransform(QList<ReferencePoint> &points);
QImage readImage(); QImage readImage();
bool readRow(QFile &file, char bits, uchar *buf); bool readRow(QFile &file, char bits, uchar *buf);