1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-07-08 08:14:28 +02:00

Use ellipsoids defined by the map file for the projection computation

This commit is contained in:
2017-04-03 20:29:35 +02:00
parent 925a0e2951
commit 6ce14734cd
11 changed files with 178 additions and 79 deletions

View File

@ -1,48 +1,11 @@
#include <cmath>
#include "rd.h"
#include "wgs84.h"
#include "lambertconic.h"
#ifndef M_PI_2
#define M_PI_2 1.57079632679489661923
#endif // M_PI_2
#ifndef M_PI_4
#define M_PI_4 0.78539816339744830962
#endif // M_PI_4
static double q(double b)
{
double e = sqrt(WGS84_FLATTENING * (2. - WGS84_FLATTENING));
double esb = e * sin(b);
return log(tan(M_PI_4 + b / 2.) * pow((1. - esb) / (1. + esb), e / 2.));
}
static double inv_q(double q)
{
double e = sqrt(WGS84_FLATTENING * (2. - WGS84_FLATTENING));
double b0 = 0.;
double b = 2. * atan(exp(q)) - M_PI_2;
do {
b0 = b;
double esb = e * sin(b);
b = 2. * atan(exp(q) * pow((1. - esb) / (1. + esb), -e / 2.)) - M_PI_2;
} while (fabs(b - b0) > 1e-10);
return b;
}
static double nradius(double phi)
{
double sin_phi = sin(phi);
return (WGS84_RADIUS / sqrt(1. - (WGS84_FLATTENING
* (2. - WGS84_FLATTENING)) * sin_phi * sin_phi));
}
LambertConic::LambertConic(double standardParallel1, double standardParallel2,
double centralParallel, double centralMeridian, double scale,
double falseEasting, double falseNorthing)
LambertConic::LambertConic(const Ellipsoid &ellipsoid, double standardParallel1,
double standardParallel2, double centralParallel, double centralMeridian,
double scale, double falseEasting, double falseNorthing) : _e(ellipsoid)
{
_cm = centralMeridian;
_fe = falseEasting;
@ -51,12 +14,12 @@ LambertConic::LambertConic(double standardParallel1, double standardParallel2,
double sp1 = deg2rad(standardParallel1);
double sp2 = deg2rad(standardParallel2);
double N1 = nradius(sp1);
double N2 = nradius(sp2);
double N1 = _e.nradius(sp1);
double N2 = _e.nradius(sp2);
_q0 = q(deg2rad(centralParallel));
double q1 = q(sp1);
double q2 = q(sp2);
_q0 = ellipsoid.q(deg2rad(centralParallel));
double q1 = _e.q(sp1);
double q2 = _e.q(sp2);
_n = log((N1 * cos(sp1)) / (N2 * cos(sp2))) / (q2 - q1);
double R1 = N1 * cos(sp1) / _n;
@ -66,7 +29,7 @@ LambertConic::LambertConic(double standardParallel1, double standardParallel2,
QPointF LambertConic::ll2xy(const Coordinates &c) const
{
double dl = _n * (deg2rad(c.lon()) - deg2rad(_cm));
double R = _R0 * exp(_n * (_q0 - q(deg2rad(c.lat()))));
double R = _R0 * exp(_n * (_q0 - _e.q(deg2rad(c.lat()))));
return QPointF(_fe + R * sin(dl), _fn + _R0 - R * cos(dl));
}
@ -79,5 +42,5 @@ Coordinates LambertConic::xy2ll(const QPointF &p) const
double R = sqrt(dx * dx + dy * dy);
double q = _q0 - log(R / _R0) / _n;
return Coordinates(rad2deg(deg2rad(_cm) + dl / _n), rad2deg(inv_q(q)));
return Coordinates(rad2deg(deg2rad(_cm) + dl / _n), rad2deg(_e.iq(q)));
}