1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-28 13:41:16 +01:00
GPXSee/src/map/crs.cpp

82 lines
1.5 KiB
C++
Raw Normal View History

#include <QStringList>
#include "pcs.h"
#include "crs.h"
Projection CRS::projection(const QString &crs)
{
QStringList list(crs.split(':'));
QString authority, code;
bool res;
switch (list.size()) {
case 2:
authority = list.at(0);
code = list.at(1);
break;
case 6:
authority = list.at(4);
code = list.at(5);
break;
case 7:
authority = list.at(4);
code = list.at(6);
break;
case 8:
authority = list.at(4);
code = list.at(7);
break;
default:
return Projection();
}
if (!authority.compare("EPSG", Qt::CaseInsensitive)) {
2021-06-17 21:58:25 +02:00
int epsg = code.toInt(&res);
if (!res)
return Projection();
PCS pcs(PCS::pcs(epsg));
2021-06-17 21:58:25 +02:00
if (!pcs.isNull())
return Projection(pcs);
2021-06-17 21:58:25 +02:00
GCS gcs(GCS::gcs(epsg));
2021-06-17 21:58:25 +02:00
if (!gcs.isNull())
return Projection(gcs);
2021-06-17 21:58:25 +02:00
return Projection();
} else if (!authority.compare("OGC", Qt::CaseInsensitive)) {
if (code == "CRS84")
2018-04-05 21:13:48 +02:00
return Projection(GCS::gcs(4326), CoordinateSystem::XY);
else
return Projection();
} else
return Projection();
}
2021-06-17 21:58:25 +02:00
Projection CRS::projection(int id)
{
PCS pcs(PCS::pcs(id));
2021-06-17 21:58:25 +02:00
if (!pcs.isNull())
return Projection(pcs);
// Geographic 2D projections
GCS gcs(GCS::gcs(id));
2021-06-17 21:58:25 +02:00
if (!gcs.isNull())
return Projection(gcs);
return Projection();
}
Projection CRS::projection(int gcsId, int projId)
{
Conversion proj(Conversion::conversion(projId));
if (!proj.isNull())
return Projection(PCS(GCS::gcs(gcsId), proj));
// Geographic 2D projections
GCS gcs(GCS::gcs(projId));
if (!gcs.isNull())
return Projection(gcs);
return Projection();
}