From 121a262ea1130032b2012f53937999f2eba9f9a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Thu, 26 Jul 2018 23:51:11 +0200 Subject: [PATCH] Remaining WGS84 deduplication --- src/map/datum.cpp | 17 ++++++++++------- src/map/datum.h | 2 ++ src/map/gcs.cpp | 3 +-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/map/datum.cpp b/src/map/datum.cpp index 10b9db49..409b2bf6 100644 --- a/src/map/datum.cpp +++ b/src/map/datum.cpp @@ -7,9 +7,6 @@ #define ds2scale(x) (1.0 + (x) * 1e-6) #define scale2ds(x) (((x) - 1.0) / 1e-6) -static Ellipsoid WGS84e = Ellipsoid(WGS84_RADIUS, WGS84_FLATTENING); -static Datum WGS84 = Datum(&WGS84e, 0.0, 0.0, 0.0); - static Coordinates molodensky(const Coordinates &c, const Datum &from, const Datum &to) { @@ -46,6 +43,12 @@ static Coordinates molodensky(const Coordinates &c, const Datum &from, return Coordinates(c.lon() + rad2deg(dlon), c.lat() + rad2deg(dlat)); } +const Datum &Datum::WGS84() +{ + static Datum d(&Ellipsoid::WGS84(), 0.0, 0.0, 0.0); + return d; +} + Point3D Datum::helmert(const Point3D &p) const { return Point3D(_scale * (p.x() + _rz * p.y() -_ry * p.z()) + _dx, @@ -92,9 +95,9 @@ Coordinates Datum::toWGS84(const Coordinates &c) const switch (_transformation) { case Helmert: return Geocentric::toGeodetic(helmert(Geocentric::fromGeodetic(c, - ellipsoid())), WGS84.ellipsoid()); + ellipsoid())), WGS84().ellipsoid()); case Molodensky: - return molodensky(c, *this, WGS84); + return molodensky(c, *this, WGS84()); default: return c; } @@ -105,9 +108,9 @@ Coordinates Datum::fromWGS84(const Coordinates &c) const switch (_transformation) { case Helmert: return Geocentric::toGeodetic(helmertr(Geocentric::fromGeodetic(c, - WGS84.ellipsoid())), ellipsoid()); + WGS84().ellipsoid())), ellipsoid()); case Molodensky: - return molodensky(c, WGS84, *this); + return molodensky(c, WGS84(), *this); default: return c; } diff --git a/src/map/datum.h b/src/map/datum.h index 29aa2708..26ea027d 100644 --- a/src/map/datum.h +++ b/src/map/datum.h @@ -35,6 +35,8 @@ public: Coordinates toWGS84(const Coordinates &c) const; Coordinates fromWGS84(const Coordinates &c) const; + static const Datum &WGS84(); + private: enum TransformationType { None, diff --git a/src/map/gcs.cpp b/src/map/gcs.cpp index cb1306d8..b1d2f8e5 100644 --- a/src/map/gcs.cpp +++ b/src/map/gcs.cpp @@ -46,8 +46,7 @@ QList GCS::_gcss = defaults(); const GCS &GCS::WGS84() { - static Datum d(&Ellipsoid::WGS84(), 0.0, 0.0, 0.0); - static GCS g(d, 8901, 9122); + static GCS g(Datum::WGS84(), 8901, 9122); return g; }