2018-01-09 09:35:56 +01:00
|
|
|
#include <QFile>
|
2018-01-20 23:51:39 +01:00
|
|
|
#include "angularunits.h"
|
2018-01-08 23:47:45 +01:00
|
|
|
#include "pcs.h"
|
|
|
|
|
|
|
|
|
|
|
|
class PCS::Entry {
|
|
|
|
public:
|
2018-01-20 20:13:56 +01:00
|
|
|
Entry(int id, int proj, const PCS &pcs) : _id(id), _proj(proj), _pcs(pcs) {}
|
2018-01-08 23:47:45 +01:00
|
|
|
|
|
|
|
int id() const {return _id;}
|
|
|
|
int proj() const {return _proj;}
|
|
|
|
const PCS &pcs() const {return _pcs;}
|
|
|
|
|
|
|
|
private:
|
2018-01-20 20:13:56 +01:00
|
|
|
int _id, _proj;
|
2018-01-08 23:47:45 +01:00
|
|
|
PCS _pcs;
|
|
|
|
};
|
|
|
|
|
|
|
|
QList<PCS::Entry> PCS::_pcss;
|
|
|
|
|
2018-01-20 23:51:39 +01:00
|
|
|
static bool parameter(int key, double val, int units, Projection::Setup &setup)
|
2018-01-08 23:47:45 +01:00
|
|
|
{
|
2018-01-20 23:51:39 +01:00
|
|
|
switch (key) {
|
|
|
|
case 8801:
|
2018-03-11 01:10:24 +01:00
|
|
|
case 8811:
|
2018-01-20 23:51:39 +01:00
|
|
|
case 8821:
|
|
|
|
{AngularUnits au(units);
|
|
|
|
if (au.isNull())
|
|
|
|
return false;
|
2018-01-21 00:47:51 +01:00
|
|
|
setup.setLatitudeOrigin(au.toDegrees(val));}
|
2018-01-20 23:51:39 +01:00
|
|
|
return true;
|
|
|
|
case 8802:
|
2018-03-11 01:10:24 +01:00
|
|
|
case 8812:
|
2018-01-20 23:51:39 +01:00
|
|
|
case 8822:
|
2018-05-29 00:17:20 +02:00
|
|
|
case 8833:
|
2018-01-20 23:51:39 +01:00
|
|
|
{AngularUnits au(units);
|
|
|
|
if (au.isNull())
|
|
|
|
return false;
|
2018-01-21 00:47:51 +01:00
|
|
|
setup.setLongitudeOrigin(au.toDegrees(val));}
|
2018-01-20 23:51:39 +01:00
|
|
|
return true;
|
|
|
|
case 8805:
|
2018-03-11 01:10:24 +01:00
|
|
|
case 8815:
|
2018-05-29 00:17:20 +02:00
|
|
|
case 8819:
|
2018-01-20 23:51:39 +01:00
|
|
|
setup.setScale(val);
|
|
|
|
return true;
|
|
|
|
case 8806:
|
2018-03-11 01:10:24 +01:00
|
|
|
case 8816:
|
2018-01-20 23:51:39 +01:00
|
|
|
case 8826:
|
|
|
|
{LinearUnits lu(units);
|
|
|
|
if (lu.isNull())
|
|
|
|
return false;
|
|
|
|
setup.setFalseEasting(lu.toMeters(val));}
|
|
|
|
return true;
|
|
|
|
case 8807:
|
2018-03-11 01:10:24 +01:00
|
|
|
case 8817:
|
2018-01-20 23:51:39 +01:00
|
|
|
case 8827:
|
|
|
|
{LinearUnits lu(units);
|
|
|
|
if (lu.isNull())
|
|
|
|
return false;
|
|
|
|
setup.setFalseNorthing(lu.toMeters(val));}
|
|
|
|
return true;
|
2018-03-11 01:10:24 +01:00
|
|
|
case 8813:
|
2018-05-29 00:17:20 +02:00
|
|
|
case 8818:
|
2018-01-20 23:51:39 +01:00
|
|
|
case 8823:
|
|
|
|
{AngularUnits au(units);
|
|
|
|
if (au.isNull())
|
|
|
|
return false;
|
|
|
|
setup.setStandardParallel1(au.toDegrees(val));}
|
|
|
|
return true;
|
2018-05-29 00:17:20 +02:00
|
|
|
case 1036:
|
2018-03-11 01:10:24 +01:00
|
|
|
case 8814:
|
2018-01-20 23:51:39 +01:00
|
|
|
case 8824:
|
|
|
|
{AngularUnits au(units);
|
|
|
|
if (au.isNull())
|
|
|
|
return false;
|
|
|
|
setup.setStandardParallel2(au.toDegrees(val));}
|
|
|
|
return true;
|
|
|
|
default:
|
2018-01-21 01:01:58 +01:00
|
|
|
return false;
|
2018-01-08 23:47:45 +01:00
|
|
|
}
|
2018-01-20 23:51:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int projectionSetup(const QList<QByteArray> &list,
|
|
|
|
Projection::Setup &setup)
|
|
|
|
{
|
2018-01-21 01:01:58 +01:00
|
|
|
bool r1, r2, r3;
|
2018-01-08 23:47:45 +01:00
|
|
|
|
2018-04-05 20:38:23 +02:00
|
|
|
for (int i = 7; i < 28; i += 3) {
|
2018-01-21 01:01:58 +01:00
|
|
|
QString ks = list[i].trimmed();
|
|
|
|
if (ks.isEmpty())
|
|
|
|
break;
|
|
|
|
|
|
|
|
int key = ks.toInt(&r1);
|
|
|
|
double val = list[i+1].trimmed().toDouble(&r2);
|
|
|
|
int un = list[i+2].trimmed().toInt(&r3);
|
|
|
|
if (!r1 || !r2 || !r3)
|
2018-04-05 20:38:23 +02:00
|
|
|
return (i - 7)/3 + 1;
|
2018-01-20 23:51:39 +01:00
|
|
|
|
|
|
|
if (!parameter(key, val, un, setup))
|
2018-04-05 20:38:23 +02:00
|
|
|
return (i - 7)/3 + 1;
|
2018-01-20 23:51:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2018-01-08 23:47:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-20 20:13:56 +01:00
|
|
|
const PCS *PCS::pcs(int id)
|
2018-01-08 23:47:45 +01:00
|
|
|
{
|
2018-01-20 20:13:56 +01:00
|
|
|
for (int i = 0; i < _pcss.size(); i++)
|
|
|
|
if (_pcss.at(i).id() == id)
|
|
|
|
return &(_pcss.at(i).pcs());
|
2018-01-08 23:47:45 +01:00
|
|
|
|
2018-01-20 20:13:56 +01:00
|
|
|
return 0;
|
2018-01-08 23:47:45 +01:00
|
|
|
}
|
|
|
|
|
2018-01-20 20:13:56 +01:00
|
|
|
const PCS *PCS::pcs(const GCS *gcs, int proj)
|
2018-01-09 23:19:35 +01:00
|
|
|
{
|
2018-01-20 20:13:56 +01:00
|
|
|
for (int i = 0; i < _pcss.size(); i++)
|
|
|
|
if (_pcss.at(i).proj() == proj && *(_pcss.at(i).pcs().gcs()) == *gcs)
|
|
|
|
return &(_pcss.at(i).pcs());
|
|
|
|
|
|
|
|
return 0;
|
2018-01-09 23:19:35 +01:00
|
|
|
}
|
|
|
|
|
2018-01-20 20:13:56 +01:00
|
|
|
void PCS::loadList(const QString &path)
|
2018-01-08 23:47:45 +01:00
|
|
|
{
|
|
|
|
QFile file(path);
|
2018-01-20 20:13:56 +01:00
|
|
|
bool res;
|
2018-01-20 23:51:39 +01:00
|
|
|
int ln = 0, pn;
|
|
|
|
const GCS *gcs;
|
2018-01-08 23:47:45 +01:00
|
|
|
|
|
|
|
if (!file.open(QFile::ReadOnly)) {
|
2018-01-20 20:13:56 +01:00
|
|
|
qWarning("Error opening PCS file: %s: %s", qPrintable(path),
|
|
|
|
qPrintable(file.errorString()));
|
|
|
|
return;
|
2018-01-08 23:47:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
while (!file.atEnd()) {
|
2018-01-20 20:13:56 +01:00
|
|
|
ln++;
|
|
|
|
|
2018-01-08 23:47:45 +01:00
|
|
|
QByteArray line = file.readLine();
|
|
|
|
QList<QByteArray> list = line.split(',');
|
2018-04-05 20:38:23 +02:00
|
|
|
if (list.size() != 28) {
|
|
|
|
qWarning("%s:%d: Format error", qPrintable(path), ln);
|
2018-01-20 20:13:56 +01:00
|
|
|
continue;
|
2018-01-08 23:47:45 +01:00
|
|
|
}
|
|
|
|
|
2018-01-20 20:13:56 +01:00
|
|
|
int id = list[1].trimmed().toInt(&res);
|
|
|
|
if (!res) {
|
2018-04-05 20:38:23 +02:00
|
|
|
qWarning("%s:%d: Invalid PCS code", qPrintable(path), ln);
|
2018-01-20 20:13:56 +01:00
|
|
|
continue;
|
2018-01-08 23:47:45 +01:00
|
|
|
}
|
2018-01-20 23:51:39 +01:00
|
|
|
int gcsid = list[2].trimmed().toInt(&res);
|
2018-01-20 20:13:56 +01:00
|
|
|
if (!res) {
|
2018-04-05 20:38:23 +02:00
|
|
|
qWarning("%s:%d: Invalid GCS code", qPrintable(path), ln);
|
2018-01-20 20:13:56 +01:00
|
|
|
continue;
|
2018-01-08 23:47:45 +01:00
|
|
|
}
|
2018-01-20 20:13:56 +01:00
|
|
|
int proj = list[3].trimmed().toInt(&res);
|
|
|
|
if (!res) {
|
2018-04-05 20:38:23 +02:00
|
|
|
qWarning("%s:%d: Invalid projection code", qPrintable(path), ln);
|
2018-01-20 20:13:56 +01:00
|
|
|
continue;
|
|
|
|
}
|
2018-01-20 23:51:39 +01:00
|
|
|
int units = list[4].trimmed().toInt(&res);
|
2018-01-20 20:13:56 +01:00
|
|
|
if (!res) {
|
2018-04-05 20:38:23 +02:00
|
|
|
qWarning("%s:%d: Invalid linear units code", qPrintable(path), ln);
|
2018-01-20 20:13:56 +01:00
|
|
|
continue;
|
|
|
|
}
|
2018-01-20 23:51:39 +01:00
|
|
|
int transform = list[5].trimmed().toInt(&res);
|
2018-01-20 20:13:56 +01:00
|
|
|
if (!res) {
|
2018-04-05 20:38:23 +02:00
|
|
|
qWarning("%s:%d: Invalid coordinate transformation code",
|
|
|
|
qPrintable(path), ln);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int cs = list[6].trimmed().toInt(&res);
|
|
|
|
if (!res) {
|
|
|
|
qWarning("%s:%d: Invalid coordinate system code",
|
2018-01-20 23:51:39 +01:00
|
|
|
qPrintable(path), ln);
|
2018-01-20 20:13:56 +01:00
|
|
|
continue;
|
|
|
|
}
|
2018-01-20 23:51:39 +01:00
|
|
|
|
2018-04-05 20:38:23 +02:00
|
|
|
if (!LinearUnits(units).isValid()) {
|
|
|
|
qWarning("%s:%d: Unknown linear units code", qPrintable(path), ln);
|
2018-01-21 11:17:32 +01:00
|
|
|
continue;
|
|
|
|
}
|
2018-04-05 20:38:23 +02:00
|
|
|
if (!Projection::Method(transform).isValid()) {
|
|
|
|
qWarning("%s:%d: Unknown coordinate transformation code",
|
2018-01-21 11:17:32 +01:00
|
|
|
qPrintable(path), ln);
|
2018-01-20 20:13:56 +01:00
|
|
|
continue;
|
|
|
|
}
|
2018-04-05 20:38:23 +02:00
|
|
|
if (!CoordinateSystem(cs).isValid()) {
|
|
|
|
qWarning("%s:%d: Unknown coordinate system code", qPrintable(path),
|
|
|
|
ln);
|
|
|
|
continue;
|
|
|
|
}
|
2018-01-20 23:51:39 +01:00
|
|
|
if (!(gcs = GCS::gcs(gcsid))) {
|
2018-04-05 20:38:23 +02:00
|
|
|
qWarning("%s:%d: Unknown GCS code", qPrintable(path), ln);
|
2018-01-20 20:13:56 +01:00
|
|
|
continue;
|
2018-01-08 23:47:45 +01:00
|
|
|
}
|
|
|
|
|
2018-01-21 11:17:32 +01:00
|
|
|
Projection::Setup setup;
|
|
|
|
if ((pn = projectionSetup(list, setup))) {
|
|
|
|
qWarning("%s: %d: Invalid projection parameter #%d",
|
|
|
|
qPrintable(path), ln, pn);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-04-05 20:38:23 +02:00
|
|
|
PCS pcs(gcs, transform, setup, units, cs);
|
2018-01-21 11:17:32 +01:00
|
|
|
_pcss.append(Entry(id, proj, pcs));
|
2018-01-08 23:47:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-13 23:03:18 +01:00
|
|
|
#ifndef QT_NO_DEBUG
|
2018-01-08 23:47:45 +01:00
|
|
|
QDebug operator<<(QDebug dbg, const PCS &pcs)
|
|
|
|
{
|
2018-01-20 23:51:39 +01:00
|
|
|
dbg.nospace() << "PCS(" << *pcs.gcs() << ", " << pcs.method() << ", "
|
|
|
|
<< pcs.units() << ", " << pcs.setup() << ")";
|
2018-01-21 11:17:32 +01:00
|
|
|
return dbg.space();
|
2018-01-08 23:47:45 +01:00
|
|
|
}
|
2018-02-13 23:03:18 +01:00
|
|
|
#endif // QT_NO_DEBUG
|