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

105 lines
2.2 KiB
C++
Raw Normal View History

2018-01-09 09:35:56 +01:00
#include <QFile>
#include "common/csv.h"
2018-01-08 23:47:45 +01:00
#include "pcs.h"
QMap<int, PCS::Entry> PCS::_pcss = defaults();
2018-01-08 23:47:45 +01:00
QMap<int, PCS::Entry> PCS::defaults()
{
QMap<int, Entry> map;
map.insert(3857, Entry("WGS 84 / Pseudo-Mercator", 4326, 3856));
return map;
}
2018-01-08 23:47:45 +01:00
PCS PCS::pcs(int id)
2018-01-08 23:47:45 +01:00
{
2023-12-26 14:14:08 +01:00
QMap<int, Entry>::const_iterator it(_pcss.find(id));
if (it == _pcss.constEnd())
return PCS();
else {
const Entry &e = it.value();
2024-03-20 07:45:49 +01:00
return PCS(GCS::gcs(e.gcs()), Conversion::conversion(e.conversion()));
}
2018-01-09 23:19:35 +01:00
}
bool PCS::loadList(const QString &path)
2018-01-08 23:47:45 +01:00
{
QFile file(path);
CSV csv(&file);
QByteArrayList entry;
bool res;
2018-01-08 23:47:45 +01:00
if (!file.open(QFile::ReadOnly)) {
qWarning("Error opening PCS file: %s: %s", qPrintable(path),
qPrintable(file.errorString()));
return false;
2018-01-08 23:47:45 +01:00
}
while (!csv.atEnd()) {
if (!csv.readEntry(entry)) {
qWarning("%s:%d: Parse error", qPrintable(path), csv.line());
return false;
2018-01-08 23:47:45 +01:00
}
if (entry.size() < 4) {
qWarning("%s:%d: Invalid column count", qPrintable(path),
csv.line() - 1);
return false;
}
QString name(entry.at(0));
int id = entry.at(1).toInt(&res);
if (!res) {
qWarning("%s:%d: Invalid PCS code", qPrintable(path),
csv.line() - 1);
continue;
2018-01-08 23:47:45 +01:00
}
int gcs = entry.at(2).toInt(&res);
if (!res) {
qWarning("%s:%d: Invalid GCS code", qPrintable(path),
csv.line() - 1);
continue;
2018-01-08 23:47:45 +01:00
}
int proj = entry.at(3).toInt(&res);
if (!res) {
qWarning("%s:%d: Invalid projection code", qPrintable(path),
csv.line() - 1);
continue;
}
if (GCS::gcs(gcs).isNull()) {
qWarning("%s:%d: Unknown GCS code", qPrintable(path),
csv.line() - 1);
continue;
2018-01-08 23:47:45 +01:00
}
if (Conversion::conversion(proj).isNull()) {
qWarning("%s:%d: Unknown projection code", qPrintable(path),
csv.line() - 1);
continue;
}
2018-01-08 23:47:45 +01:00
_pcss.insert(id, Entry(name, gcs, proj));
2018-01-08 23:47:45 +01:00
}
return true;
2018-01-08 23:47:45 +01:00
}
QList<KV<int, QString> > PCS::list()
{
QList<KV<int, QString> > list;
for (QMap<int, Entry>::const_iterator it = _pcss.constBegin();
it != _pcss.constEnd(); ++it)
list.append(KV<int, QString>(it.key(), it.value().name()));
return list;
}
#ifndef QT_NO_DEBUG
2018-01-08 23:47:45 +01:00
QDebug operator<<(QDebug dbg, const PCS &pcs)
{
dbg.nospace() << "PCS(" << pcs.gcs() << ", " << pcs.conversion() << ")";
2018-01-21 11:17:32 +01:00
return dbg.space();
2018-01-08 23:47:45 +01:00
}
#endif // QT_NO_DEBUG