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:
|
2019-05-14 23:01:24 +02:00
|
|
|
Entry(const QString &name, int id, int proj, const PCS &pcs)
|
|
|
|
: _name(name), _id(id), _proj(proj), _pcs(pcs) {}
|
2018-01-08 23:47:45 +01:00
|
|
|
|
2019-05-14 23:01:24 +02:00
|
|
|
const QString &name() const {return _name;}
|
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:
|
2019-05-14 23:01:24 +02:00
|
|
|
QString _name;
|
2018-01-20 20:13:56 +01:00
|
|
|
int _id, _proj;
|
2018-01-08 23:47:45 +01:00
|
|
|
PCS _pcs;
|
|
|
|
};
|
|
|
|
|
2018-06-28 22:12:16 +02:00
|
|
|
QList<PCS::Entry> PCS::_pcss = defaults();
|
|
|
|
|
|
|
|
QList<PCS::Entry> PCS::defaults()
|
|
|
|
{
|
|
|
|
QList<PCS::Entry> list;
|
2019-05-14 23:01:24 +02:00
|
|
|
list.append(PCS::Entry("WGS 84 / Pseudo-Mercator", 3857, 3856,
|
2021-06-17 21:58:25 +02:00
|
|
|
PCS(GCS::WGS84(), 1024, Projection::Setup(0, 0, NAN, 0, 0, NAN, NAN),
|
2019-05-14 23:01:24 +02:00
|
|
|
9001, 4499)));
|
2018-06-28 22:12:16 +02:00
|
|
|
return list;
|
|
|
|
}
|
2018-01-08 23:47:45 +01:00
|
|
|
|
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:
|
2019-01-08 21:42:28 +01:00
|
|
|
case 8832:
|
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.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
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-01 08:54:48 +02:00
|
|
|
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)
|
2021-06-17 21:58:25 +02:00
|
|
|
return _pcss.at(i).pcs();
|
2018-01-08 23:47:45 +01:00
|
|
|
|
2021-07-01 08:54:48 +02:00
|
|
|
return PCS();
|
2018-01-08 23:47:45 +01:00
|
|
|
}
|
|
|
|
|
2021-07-01 08:54:48 +02:00
|
|
|
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++)
|
2021-06-17 21:58:25 +02:00
|
|
|
if (_pcss.at(i).proj() == proj && _pcss.at(i).pcs().gcs() == gcs)
|
|
|
|
return _pcss.at(i).pcs();
|
2018-01-20 20:13:56 +01:00
|
|
|
|
2021-07-01 08:54:48 +02:00
|
|
|
return PCS();
|
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;
|
2021-06-17 21:58:25 +02:00
|
|
|
|
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++;
|
|
|
|
|
2022-07-05 11:08:57 +02:00
|
|
|
QByteArray line = file.readLine(4096);
|
2018-01-08 23:47:45 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-05-14 23:01:24 +02:00
|
|
|
QString name(list.at(0).trimmed());
|
|
|
|
int id = list.at(1).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 PCS code", qPrintable(path), ln);
|
2018-01-20 20:13:56 +01:00
|
|
|
continue;
|
2018-01-08 23:47:45 +01:00
|
|
|
}
|
2019-05-14 23:01:24 +02:00
|
|
|
int gcsid = list.at(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
|
|
|
}
|
2019-05-14 23:01:24 +02:00
|
|
|
int proj = list.at(3).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 projection code", qPrintable(path), ln);
|
2018-01-20 20:13:56 +01:00
|
|
|
continue;
|
|
|
|
}
|
2019-05-14 23:01:24 +02:00
|
|
|
int units = list.at(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;
|
|
|
|
}
|
2019-05-14 23:01:24 +02:00
|
|
|
int transform = list.at(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;
|
|
|
|
}
|
2021-07-01 08:54:48 +02:00
|
|
|
GCS gcs(GCS::gcs(gcsid));
|
2021-06-17 21:58:25 +02:00
|
|
|
if (gcs.isNull()) {
|
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);
|
2019-05-14 23:01:24 +02:00
|
|
|
_pcss.append(Entry(name, id, proj, pcs));
|
2018-01-08 23:47:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-01 08:36:58 +02:00
|
|
|
QList<KV<int, QString> > PCS::list()
|
2019-05-14 23:01:24 +02:00
|
|
|
{
|
2019-08-01 08:36:58 +02:00
|
|
|
QList<KV<int, QString> > list;
|
2019-05-14 23:01:24 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < _pcss.size(); i++)
|
2019-08-01 08:36:58 +02:00
|
|
|
list.append(KV<int, QString>(_pcss.at(i).id(), _pcss.at(i).name()));
|
2019-05-14 23:01:24 +02:00
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2021-06-17 21:58:25 +02:00
|
|
|
dbg.nospace() << "PCS(" << pcs.gcs() << ", " << pcs.method() << ", "
|
2018-01-20 23:51:39 +01:00
|
|
|
<< 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
|