1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-18 11:52:08 +01:00

Code cleanup

This commit is contained in:
Martin Tůma 2021-06-27 16:00:27 +02:00
parent f5ea667f34
commit c0c7e9046a
5 changed files with 29 additions and 20 deletions

View File

@ -289,7 +289,7 @@ bool GeoTIFF::readGeoValue(TIFFFile &file, quint32 offset, quint16 index,
return true; return true;
} }
GCS GeoTIFF::gcs(QMap<quint16, Value> &kv) GCS GeoTIFF::geographicCS(QMap<quint16, Value> &kv)
{ {
GCS gcs; GCS gcs;
@ -321,7 +321,7 @@ GCS GeoTIFF::gcs(QMap<quint16, Value> &kv)
return gcs; return gcs;
} }
Projection::Method GeoTIFF::method(QMap<quint16, Value> &kv) Projection::Method GeoTIFF::coordinateTransformation(QMap<quint16, Value> &kv)
{ {
if (!IS_SET(kv, ProjCoordTransGeoKey)) { if (!IS_SET(kv, ProjCoordTransGeoKey)) {
_errorString = "Missing coordinate transformation method"; _errorString = "Missing coordinate transformation method";
@ -367,10 +367,10 @@ bool GeoTIFF::projectedModel(QMap<quint16, Value> &kv)
} }
_projection = Projection(pcs); _projection = Projection(pcs);
} else if (IS_SET(kv, ProjectionGeoKey)) { } else if (IS_SET(kv, ProjectionGeoKey)) {
const GCS g(gcs(kv)); GCS gcs(geographicCS(kv));
if (g.isNull()) if (gcs.isNull())
return false; return false;
const PCS &pcs = PCS::pcs(g, kv.value(ProjectionGeoKey).SHORT); const PCS &pcs = PCS::pcs(gcs, kv.value(ProjectionGeoKey).SHORT);
if (pcs.isNull()) { if (pcs.isNull()) {
_errorString = QString("%1: unknown projection code") _errorString = QString("%1: unknown projection code")
.arg(kv.value(GeographicTypeGeoKey).SHORT) .arg(kv.value(GeographicTypeGeoKey).SHORT)
@ -381,11 +381,11 @@ bool GeoTIFF::projectedModel(QMap<quint16, Value> &kv)
} else { } else {
double lat0, lon0, scale, fe, fn, sp1, sp2; double lat0, lon0, scale, fe, fn, sp1, sp2;
GCS g(gcs(kv)); GCS gcs(geographicCS(kv));
if (g.isNull()) if (gcs.isNull())
return false; return false;
Projection::Method m(method(kv)); Projection::Method method(coordinateTransformation(kv));
if (m.isNull()) if (method.isNull())
return false; return false;
AngularUnits au(IS_SET(kv, GeogAngularUnitsGeoKey) AngularUnits au(IS_SET(kv, GeogAngularUnitsGeoKey)
@ -454,7 +454,7 @@ bool GeoTIFF::projectedModel(QMap<quint16, Value> &kv)
fe = NAN; fe = NAN;
Projection::Setup setup(lat0, lon0, scale, fe, fn, sp1, sp2); Projection::Setup setup(lat0, lon0, scale, fe, fn, sp1, sp2);
PCS pcs(g, m, setup, lu, CoordinateSystem()); PCS pcs(gcs, method, setup, lu, CoordinateSystem());
_projection = Projection(pcs); _projection = Projection(pcs);
} }
@ -463,11 +463,11 @@ bool GeoTIFF::projectedModel(QMap<quint16, Value> &kv)
bool GeoTIFF::geographicModel(QMap<quint16, Value> &kv) bool GeoTIFF::geographicModel(QMap<quint16, Value> &kv)
{ {
GCS g(gcs(kv)); GCS gcs(geographicCS(kv));
if (g.isNull()) if (gcs.isNull())
return false; return false;
_projection = Projection(g); _projection = Projection(gcs);
return true; return true;
} }

View File

@ -48,8 +48,8 @@ private:
bool readGeoValue(TIFFFile &file, quint32 offset, quint16 index, bool readGeoValue(TIFFFile &file, quint32 offset, quint16 index,
double &val) const; double &val) const;
GCS gcs(QMap<quint16, Value> &kv); GCS geographicCS(QMap<quint16, Value> &kv);
Projection::Method method(QMap<quint16, Value> &kv); Projection::Method coordinateTransformation(QMap<quint16, Value> &kv);
bool geographicModel(QMap<quint16, Value> &kv); bool geographicModel(QMap<quint16, Value> &kv);
bool projectedModel(QMap<quint16, Value> &kv); bool projectedModel(QMap<quint16, Value> &kv);

View File

@ -30,8 +30,9 @@ public:
&& _setup.isNull() && _cs.isNull()); && _setup.isNull() && _cs.isNull());
} }
bool isValid() const { bool isValid() const {
return (_gcs.isValid() && _units.isValid() && _method.isValid() // We do not check the CoordinateSystem here as it is not always defined
&& _cs.isValid()); // and except of WMTS/WMS it is not needed.
return (_gcs.isValid() && _units.isValid() && _method.isValid());
} }
static void loadList(const QString &path); static void loadList(const QString &path);

View File

@ -115,7 +115,7 @@ Projection::Projection(const PCS &pcs)
} }
Projection::Projection(const GCS &gcs, const CoordinateSystem &cs) Projection::Projection(const GCS &gcs, const CoordinateSystem &cs)
: _gcs(gcs), _ct(0), _units(LinearUnits(9001)), _cs(cs), _geographic(true) : _gcs(gcs), _units(LinearUnits(9001)), _cs(cs), _geographic(true)
{ {
_ct = new LatLon(gcs.angularUnits()); _ct = new LatLon(gcs.angularUnits());
} }

View File

@ -80,8 +80,16 @@ public:
Projection &operator=(const Projection &p); Projection &operator=(const Projection &p);
bool operator==(const Projection &p) const; bool operator==(const Projection &p) const;
bool isNull() const {return (_gcs.isNull() && _ct == 0 && _units.isNull());} bool isNull() const
bool isValid() const {return _gcs.isValid() && _ct != 0 && _units.isValid();} {
return (_gcs.isNull() && _ct == 0 && _units.isNull() && _cs.isNull());
}
bool isValid() const
{
// We do not check the CoordinateSystem here as it is not always defined
// and except of WMTS/WMS it is not needed.
return (_gcs.isValid() && _ct != 0 && _units.isValid());
}
bool isGeographic() const {return _geographic;} bool isGeographic() const {return _geographic;}
PointD ll2xy(const Coordinates &c) const; PointD ll2xy(const Coordinates &c) const;