GeographicLib 2.1.2
LambertConformalConic.hpp
Go to the documentation of this file.
1/**
2 * \file LambertConformalConic.hpp
3 * \brief Header for GeographicLib::LambertConformalConic class
4 *
5 * Copyright (c) Charles Karney (2010-2022) <charles@karney.com> and licensed
6 * under the MIT/X11 License. For more information, see
7 * https://geographiclib.sourceforge.io/
8 **********************************************************************/
9
10#if !defined(GEOGRAPHICLIB_LAMBERTCONFORMALCONIC_HPP)
11#define GEOGRAPHICLIB_LAMBERTCONFORMALCONIC_HPP 1
12
14
15namespace GeographicLib {
16
17 /**
18 * \brief Lambert conformal conic projection
19 *
20 * Implementation taken from the report,
21 * - J. P. Snyder,
22 * <a href="http://pubs.er.usgs.gov/usgspubs/pp/pp1395"> Map Projections: A
23 * Working Manual</a>, USGS Professional Paper 1395 (1987),
24 * pp. 107--109.
25 *
26 * This is a implementation of the equations in Snyder except that divided
27 * differences have been used to transform the expressions into ones which
28 * may be evaluated accurately and that Newton's method is used to invert the
29 * projection. In this implementation, the projection correctly becomes the
30 * Mercator projection or the polar stereographic projection when the
31 * standard latitude is the equator or a pole. The accuracy of the
32 * projections is about 10 nm (10 nanometers).
33 *
34 * The ellipsoid parameters, the standard parallels, and the scale on the
35 * standard parallels are set in the constructor. Internally, the case with
36 * two standard parallels is converted into a single standard parallel, the
37 * latitude of tangency (also the latitude of minimum scale), with a scale
38 * specified on this parallel. This latitude is also used as the latitude of
39 * origin which is returned by LambertConformalConic::OriginLatitude. The
40 * scale on the latitude of origin is given by
41 * LambertConformalConic::CentralScale. The case with two distinct standard
42 * parallels where one is a pole is singular and is disallowed. The central
43 * meridian (which is a trivial shift of the longitude) is specified as the
44 * \e lon0 argument of the LambertConformalConic::Forward and
45 * LambertConformalConic::Reverse functions.
46 *
47 * This class also returns the meridian convergence \e gamma and scale \e k.
48 * The meridian convergence is the bearing of grid north (the \e y axis)
49 * measured clockwise from true north.
50 *
51 * There is no provision in this
52 * class for specifying a false easting or false northing or a different
53 * latitude of origin. However these are can be simply included by the
54 * calling function. For example the Pennsylvania South state coordinate
55 * system (<a href="https://www.spatialreference.org/ref/epsg/3364/">
56 * EPSG:3364</a>) is obtained by:
57 * \include example-LambertConformalConic.cpp
58 *
59 * <a href="ConicProj.1.html">ConicProj</a> is a command-line utility
60 * providing access to the functionality of LambertConformalConic and
61 * AlbersEqualArea.
62 **********************************************************************/
64 private:
65 typedef Math::real real;
66 real eps_, epsx_, ahypover_;
67 real _a, _f, _fm, _e2, _es;
68 real _sign, _n, _nc, _t0nm1, _scale, _lat0, _k0;
69 real _scbet0, _tchi0, _scchi0, _psi0, _nrho0, _drhomax;
70 static const int numit_ = 5;
71 static real hyp(real x) {
72 using std::hypot;
73 return hypot(real(1), x);
74 }
75 // Divided differences
76 // Definition: Df(x,y) = (f(x)-f(y))/(x-y)
77 // See:
78 // W. M. Kahan and R. J. Fateman,
79 // Symbolic computation of divided differences,
80 // SIGSAM Bull. 33(2), 7-28 (1999)
81 // https://doi.org/10.1145/334714.334716
82 // http://www.cs.berkeley.edu/~fateman/papers/divdiff.pdf
83 //
84 // General rules
85 // h(x) = f(g(x)): Dh(x,y) = Df(g(x),g(y))*Dg(x,y)
86 // h(x) = f(x)*g(x):
87 // Dh(x,y) = Df(x,y)*g(x) + Dg(x,y)*f(y)
88 // = Df(x,y)*g(y) + Dg(x,y)*f(x)
89 // = Df(x,y)*(g(x)+g(y))/2 + Dg(x,y)*(f(x)+f(y))/2
90 //
91 // hyp(x) = sqrt(1+x^2): Dhyp(x,y) = (x+y)/(hyp(x)+hyp(y))
92 static real Dhyp(real x, real y, real hx, real hy)
93 // hx = hyp(x)
94 { return (x + y) / (hx + hy); }
95 // sn(x) = x/sqrt(1+x^2): Dsn(x,y) = (x+y)/((sn(x)+sn(y))*(1+x^2)*(1+y^2))
96 static real Dsn(real x, real y, real sx, real sy) {
97 // sx = x/hyp(x)
98 real t = x * y;
99 return t > 0 ? (x + y) * Math::sq( (sx * sy)/t ) / (sx + sy) :
100 (x - y != 0 ? (sx - sy) / (x - y) : 1);
101 }
102 // Dlog1p(x,y) = log1p((x-y)/(1+y))/(x-y)
103 static real Dlog1p(real x, real y) {
104 using std::log1p;
105 real t = x - y; if (t < 0) { t = -t; y = x; }
106 return t != 0 ? log1p(t / (1 + y)) / t : 1 / (1 + x);
107 }
108 // Dexp(x,y) = exp((x+y)/2) * 2*sinh((x-y)/2)/(x-y)
109 static real Dexp(real x, real y) {
110 using std::sinh; using std::exp;
111 real t = (x - y)/2;
112 return (t != 0 ? sinh(t)/t : 1) * exp((x + y)/2);
113 }
114 // Dsinh(x,y) = 2*sinh((x-y)/2)/(x-y) * cosh((x+y)/2)
115 // cosh((x+y)/2) = (c+sinh(x)*sinh(y)/c)/2
116 // c=sqrt((1+cosh(x))*(1+cosh(y)))
117 // cosh((x+y)/2) = sqrt( (sinh(x)*sinh(y) + cosh(x)*cosh(y) + 1)/2 )
118 static real Dsinh(real x, real y, real sx, real sy, real cx, real cy)
119 // sx = sinh(x), cx = cosh(x)
120 {
121 // real t = (x - y)/2, c = sqrt((1 + cx) * (1 + cy));
122 // return (t ? sinh(t)/t : real(1)) * (c + sx * sy / c) /2;
123 using std::sinh; using std::sqrt;
124 real t = (x - y)/2;
125 return (t != 0 ? sinh(t)/t : 1) * sqrt((sx * sy + cx * cy + 1) /2);
126 }
127 // Dasinh(x,y) = asinh((x-y)*(x+y)/(x*sqrt(1+y^2)+y*sqrt(1+x^2)))/(x-y)
128 // = asinh((x*sqrt(1+y^2)-y*sqrt(1+x^2)))/(x-y)
129 static real Dasinh(real x, real y, real hx, real hy) {
130 // hx = hyp(x)
131 using std::asinh;
132 real t = x - y;
133 return t != 0 ?
134 asinh(x*y > 0 ? t * (x + y) / (x*hy + y*hx) : x*hy - y*hx) / t :
135 1 / hx;
136 }
137 // Deatanhe(x,y) = eatanhe((x-y)/(1-e^2*x*y))/(x-y)
138 real Deatanhe(real x, real y) const {
139 real t = x - y, d = 1 - _e2 * x * y;
140 return t != 0 ? Math::eatanhe(t / d, _es) / t : _e2 / d;
141 }
142 void Init(real sphi1, real cphi1, real sphi2, real cphi2, real k1);
143 public:
144
145 /**
146 * Constructor with a single standard parallel.
147 *
148 * @param[in] a equatorial radius of ellipsoid (meters).
149 * @param[in] f flattening of ellipsoid. Setting \e f = 0 gives a sphere.
150 * Negative \e f gives a prolate ellipsoid.
151 * @param[in] stdlat standard parallel (degrees), the circle of tangency.
152 * @param[in] k0 scale on the standard parallel.
153 * @exception GeographicErr if \e a, (1 &minus; \e f) \e a, or \e k0 is
154 * not positive.
155 * @exception GeographicErr if \e stdlat is not in [&minus;90&deg;,
156 * 90&deg;].
157 **********************************************************************/
158 LambertConformalConic(real a, real f, real stdlat, real k0);
159
160 /**
161 * Constructor with two standard parallels.
162 *
163 * @param[in] a equatorial radius of ellipsoid (meters).
164 * @param[in] f flattening of ellipsoid. Setting \e f = 0 gives a sphere.
165 * Negative \e f gives a prolate ellipsoid.
166 * @param[in] stdlat1 first standard parallel (degrees).
167 * @param[in] stdlat2 second standard parallel (degrees).
168 * @param[in] k1 scale on the standard parallels.
169 * @exception GeographicErr if \e a, (1 &minus; \e f) \e a, or \e k1 is
170 * not positive.
171 * @exception GeographicErr if \e stdlat1 or \e stdlat2 is not in
172 * [&minus;90&deg;, 90&deg;], or if either \e stdlat1 or \e
173 * stdlat2 is a pole and \e stdlat1 is not equal \e stdlat2.
174 **********************************************************************/
175 LambertConformalConic(real a, real f, real stdlat1, real stdlat2, real k1);
176
177 /**
178 * Constructor with two standard parallels specified by sines and cosines.
179 *
180 * @param[in] a equatorial radius of ellipsoid (meters).
181 * @param[in] f flattening of ellipsoid. Setting \e f = 0 gives a sphere.
182 * Negative \e f gives a prolate ellipsoid.
183 * @param[in] sinlat1 sine of first standard parallel.
184 * @param[in] coslat1 cosine of first standard parallel.
185 * @param[in] sinlat2 sine of second standard parallel.
186 * @param[in] coslat2 cosine of second standard parallel.
187 * @param[in] k1 scale on the standard parallels.
188 * @exception GeographicErr if \e a, (1 &minus; \e f) \e a, or \e k1 is
189 * not positive.
190 * @exception GeographicErr if \e stdlat1 or \e stdlat2 is not in
191 * [&minus;90&deg;, 90&deg;], or if either \e stdlat1 or \e
192 * stdlat2 is a pole and \e stdlat1 is not equal \e stdlat2.
193 *
194 * This allows parallels close to the poles to be specified accurately.
195 * This routine computes the latitude of origin and the scale at this
196 * latitude. In the case where \e lat1 and \e lat2 are different, the
197 * errors in this routines are as follows: if \e dlat = abs(\e lat2 &minus;
198 * \e lat1) &le; 160&deg; and max(abs(\e lat1), abs(\e lat2)) &le; 90
199 * &minus; min(0.0002, 2.2 &times; 10<sup>&minus;6</sup>(180 &minus; \e
200 * dlat), 6 &times 10<sup>&minus;8</sup> <i>dlat</i><sup>2</sup>) (in
201 * degrees), then the error in the latitude of origin is less than 4.5
202 * &times; 10<sup>&minus;14</sup>d and the relative error in the scale is
203 * less than 7 &times; 10<sup>&minus;15</sup>.
204 **********************************************************************/
205 LambertConformalConic(real a, real f,
206 real sinlat1, real coslat1,
207 real sinlat2, real coslat2,
208 real k1);
209
210 /**
211 * Set the scale for the projection.
212 *
213 * @param[in] lat (degrees).
214 * @param[in] k scale at latitude \e lat (default 1).
215 * @exception GeographicErr \e k is not positive.
216 * @exception GeographicErr if \e lat is not in [&minus;90&deg;,
217 * 90&deg;].
218 **********************************************************************/
219 void SetScale(real lat, real k = real(1));
220
221 /**
222 * Forward projection, from geographic to Lambert conformal conic.
223 *
224 * @param[in] lon0 central meridian longitude (degrees).
225 * @param[in] lat latitude of point (degrees).
226 * @param[in] lon longitude of point (degrees).
227 * @param[out] x easting of point (meters).
228 * @param[out] y northing of point (meters).
229 * @param[out] gamma meridian convergence at point (degrees).
230 * @param[out] k scale of projection at point.
231 *
232 * The latitude origin is given by LambertConformalConic::LatitudeOrigin().
233 * No false easting or northing is added and \e lat should be in the range
234 * [&minus;90&deg;, 90&deg;]. The error in the projection is less than
235 * about 10 nm (10 nanometers), true distance, and the errors in the
236 * meridian convergence and scale are consistent with this. The values of
237 * \e x and \e y returned for points which project to infinity (i.e., one
238 * or both of the poles) will be large but finite.
239 **********************************************************************/
240 void Forward(real lon0, real lat, real lon,
241 real& x, real& y, real& gamma, real& k) const;
242
243 /**
244 * Reverse projection, from Lambert conformal conic to geographic.
245 *
246 * @param[in] lon0 central meridian longitude (degrees).
247 * @param[in] x easting of point (meters).
248 * @param[in] y northing of point (meters).
249 * @param[out] lat latitude of point (degrees).
250 * @param[out] lon longitude of point (degrees).
251 * @param[out] gamma meridian convergence at point (degrees).
252 * @param[out] k scale of projection at point.
253 *
254 * The latitude origin is given by LambertConformalConic::LatitudeOrigin().
255 * No false easting or northing is added. The value of \e lon returned is
256 * in the range [&minus;180&deg;, 180&deg;]. The error in the projection
257 * is less than about 10 nm (10 nanometers), true distance, and the errors
258 * in the meridian convergence and scale are consistent with this.
259 **********************************************************************/
260 void Reverse(real lon0, real x, real y,
261 real& lat, real& lon, real& gamma, real& k) const;
262
263 /**
264 * LambertConformalConic::Forward without returning the convergence and
265 * scale.
266 **********************************************************************/
267 void Forward(real lon0, real lat, real lon,
268 real& x, real& y) const {
269 real gamma, k;
270 Forward(lon0, lat, lon, x, y, gamma, k);
271 }
272
273 /**
274 * LambertConformalConic::Reverse without returning the convergence and
275 * scale.
276 **********************************************************************/
277 void Reverse(real lon0, real x, real y,
278 real& lat, real& lon) const {
279 real gamma, k;
280 Reverse(lon0, x, y, lat, lon, gamma, k);
281 }
282
283 /** \name Inspector functions
284 **********************************************************************/
285 ///@{
286 /**
287 * @return \e a the equatorial radius of the ellipsoid (meters). This is
288 * the value used in the constructor.
289 **********************************************************************/
290 Math::real EquatorialRadius() const { return _a; }
291
292 /**
293 * @return \e f the flattening of the ellipsoid. This is the
294 * value used in the constructor.
295 **********************************************************************/
296 Math::real Flattening() const { return _f; }
297
298 /**
299 * @return latitude of the origin for the projection (degrees).
300 *
301 * This is the latitude of minimum scale and equals the \e stdlat in the
302 * 1-parallel constructor and lies between \e stdlat1 and \e stdlat2 in the
303 * 2-parallel constructors.
304 **********************************************************************/
305 Math::real OriginLatitude() const { return _lat0; }
306
307 /**
308 * @return central scale for the projection. This is the scale on the
309 * latitude of origin.
310 **********************************************************************/
311 Math::real CentralScale() const { return _k0; }
312 ///@}
313
314 /**
315 * A global instantiation of LambertConformalConic with the WGS84
316 * ellipsoid, \e stdlat = 0, and \e k0 = 1. This degenerates to the
317 * Mercator projection.
318 **********************************************************************/
319 static const LambertConformalConic& Mercator();
320 };
321
322} // namespace GeographicLib
323
324#endif // GEOGRAPHICLIB_LAMBERTCONFORMALCONIC_HPP
Header for GeographicLib::Constants class.
#define GEOGRAPHICLIB_EXPORT
Definition: Constants.hpp:67
GeographicLib::Math::real real
Definition: GeodSolve.cpp:31
Lambert conformal conic projection.
void Forward(real lon0, real lat, real lon, real &x, real &y) const
void Reverse(real lon0, real x, real y, real &lat, real &lon) const
static T sq(T x)
Definition: Math.hpp:212
static T eatanhe(T x, T es)
Definition: Math.cpp:205
Namespace for GeographicLib.
Definition: Accumulator.cpp:12