From 2c816a509b5aba426fd3c5528f65d4611b32055a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Tue, 29 May 2018 21:54:25 +0200 Subject: [PATCH] Refactoring --- src/map/krovak.cpp | 24 ++++++++++-------------- src/map/krovak.h | 29 +++++++++++++++++++++-------- src/map/projection.cpp | 6 +++--- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/map/krovak.cpp b/src/map/krovak.cpp index 36e458b5..b3f27515 100644 --- a/src/map/krovak.cpp +++ b/src/map/krovak.cpp @@ -3,7 +3,7 @@ Krovak::Krovak(const Ellipsoid *ellipsoid, double standardParallel, double azimuth, double scale, double centerLatitude, double longitudeOrigin, - double falseEasting, double falseNorthing, Orientation orientation) + double falseEasting, double falseNorthing) { double phiC = deg2rad(centerLatitude); double sinPhiC = sin(phiC); @@ -28,34 +28,30 @@ Krovak::Krovak(const Ellipsoid *ellipsoid, double standardParallel, _cosAlphaC = cos(alphaC); _sinAlphaC = sin(alphaC); _lambda0 = deg2rad(longitudeOrigin); - _orientation = orientation; } PointD Krovak::ll2xy(const Coordinates &c) const { double phi = deg2rad(c.lat()); double lambda = deg2rad(c.lon()); - double sinPhi = sin(phi); - double eSinPhi = _e * sinPhi; - + double eSinPhi = _e * sin(phi); double U = 2.0 * (atan(_t0 * pow(tan(phi/2.0 + M_PI_4), _B) - / pow((1.0 + eSinPhi) / (1.0 - eSinPhi), _e * _B / 2.0)) - M_PI_4); + / pow((1.0 + eSinPhi) / (1.0 - eSinPhi), _e * _B/2.0)) - M_PI_4); + double cosU = cos(U); double V = _B * (_lambda0 - lambda); - double T = asin(_cosAlphaC * sin(U) + _sinAlphaC * cos(U) * cos(V)); - double D = asin(cos(U) * sin(V) / cos(T)); + double T = asin(_cosAlphaC * sin(U) + _sinAlphaC * cosU * cos(V)); + double D = asin(cosU * sin(V) / cos(T)); double theta = _n * D; - double r = _r0 * pow(tan(M_PI_4 + _phiP / 2.0), _n) + double r = _r0 * pow(tan(M_PI_4 + _phiP/2.0), _n) / pow(tan(T/2.0 + M_PI_4), _n); - double sign = (_orientation == North) ? -1.0 : 1.0; - return PointD(sign * (r * sin(theta) + _FE), sign * (r * cos(theta) + _FN)); + return PointD(r * sin(theta) + _FE, r * cos(theta) + _FN); } Coordinates Krovak::xy2ll(const PointD &p) const { - double sign = (_orientation == North) ? -1.0 : 1.0; - double Xp = sign * p.y() - _FN; - double Yp = sign * p.x() - _FE; + double Xp = p.y() - _FN; + double Yp = p.x() - _FE; double Xp2 = Xp * Xp; double Yp2 = Yp * Yp; double r = sqrt(Xp2 + Yp2); diff --git a/src/map/krovak.h b/src/map/krovak.h index f7c4a3c8..3139d78f 100644 --- a/src/map/krovak.h +++ b/src/map/krovak.h @@ -8,15 +8,9 @@ class Ellipsoid; class Krovak : public CT { public: - enum Orientation { - North, - South - }; - Krovak(const Ellipsoid *ellipsoid, double standardParallel, double azimuth, double scale, double centerLatitude, - double longitudeOrigin, double falseEasting, double falseNorthing, - Orientation orientation); + double longitudeOrigin, double falseEasting, double falseNorthing); virtual CT *clone() const {return new Krovak(*this);} @@ -26,7 +20,26 @@ public: private: double _e, _A, _B, _t0, _n, _r0, _phiP; double _cosAlphaC, _sinAlphaC, _lambda0, _FE, _FN; - Orientation _orientation; +}; + +class KrovakNE : public CT +{ +public: + KrovakNE(const Ellipsoid *ellipsoid, double standardParallel, + double azimuth, double scale, double centerLatitude, + double longitudeOrigin, double falseEasting, double falseNorthing) + : _k(ellipsoid, standardParallel, azimuth, scale, centerLatitude, + longitudeOrigin, falseEasting, falseNorthing) {} + + virtual CT *clone() const {return new KrovakNE(*this);} + + virtual PointD ll2xy(const Coordinates &c) const + {PointD p(_k.ll2xy(c)); return PointD(-p.x(), -p.y());} + virtual Coordinates xy2ll(const PointD &p) const + {return _k.xy2ll(PointD(-p.x(), -p.y()));} + +private: + Krovak _k; }; #endif // KROVAK_H diff --git a/src/map/projection.cpp b/src/map/projection.cpp index 321cb6de..b948c135 100644 --- a/src/map/projection.cpp +++ b/src/map/projection.cpp @@ -43,10 +43,10 @@ Projection::Projection(const PCS *pcs) : _gcs(pcs->gcs()), _units(pcs->units()), _ct = new WebMercator(); break; case 1041: - _ct = new Krovak(ellipsoid, setup.standardParallel1(), + _ct = new KrovakNE(ellipsoid, setup.standardParallel1(), setup.standardParallel2(), setup.scale(), setup.latitudeOrigin(), setup.longitudeOrigin(), setup.falseEasting(), - setup.falseNorthing(), Krovak::North); + setup.falseNorthing()); break; case 9801: case 9815: // Oblique mercator aproximation using LCC1 @@ -74,7 +74,7 @@ Projection::Projection(const PCS *pcs) : _gcs(pcs->gcs()), _units(pcs->units()), _ct = new Krovak(ellipsoid, setup.standardParallel1(), setup.standardParallel2(), setup.scale(), setup.latitudeOrigin(), setup.longitudeOrigin(), setup.falseEasting(), - setup.falseNorthing(), Krovak::South); + setup.falseNorthing()); break; case 9820: _ct = new LambertAzimuthal(ellipsoid, setup.latitudeOrigin(),