Coverage for pygeodesy/etm.py: 92%
409 statements
« prev ^ index » next coverage.py v7.6.0, created at 2024-08-02 18:24 -0400
« prev ^ index » next coverage.py v7.6.0, created at 2024-08-02 18:24 -0400
2# -*- coding: utf-8 -*-
4u'''A pure Python version of I{Karney}'s C{Exact Transverse Mercator} (ETM) projection.
6Classes L{Etm}, L{ETMError} and L{ExactTransverseMercator}, transcoded from I{Karney}'s
7C++ class U{TransverseMercatorExact<https://GeographicLib.SourceForge.io/C++/doc/
8classGeographicLib_1_1TransverseMercatorExact.html>}, abbreviated as C{TMExact} below.
10Class L{ExactTransverseMercator} provides C{Exact Transverse Mercator} projections while
11instances of class L{Etm} represent ETM C{(easting, northing)} locations. See also
12I{Karney}'s utility U{TransverseMercatorProj<https://GeographicLib.SourceForge.io/C++/doc/
13TransverseMercatorProj.1.html>} and use C{"python[3] -m pygeodesy.etm ..."} to compare
14the results.
16Following is a copy of I{Karney}'s U{TransverseMercatorExact.hpp
17<https://GeographicLib.SourceForge.io/C++/doc/TransverseMercatorExact_8hpp_source.html>}
18file C{Header}.
20Copyright (C) U{Charles Karney<mailto:Karney@Alum.MIT.edu>} (2008-2023) and licensed
21under the MIT/X11 License. For more information, see the U{GeographicLib<https://
22GeographicLib.SourceForge.io>} documentation.
24The method entails using the U{Thompson Transverse Mercator<https://WikiPedia.org/
25wiki/Transverse_Mercator_projection>} as an intermediate projection. The projections
26from the intermediate coordinates to C{phi, lam} and C{x, y} are given by elliptic
27functions. The inverse of these projections are found by Newton's method with a
28suitable starting guess.
30The relevant section of L.P. Lee's paper U{Conformal Projections Based On Jacobian
31Elliptic Functions<https://DOI.org/10.3138/X687-1574-4325-WM62>} in part V, pp
3267-101. The C++ implementation and notation closely follow Lee, with the following
33exceptions::
35 Lee here Description
37 x/a xi Northing (unit Earth)
39 y/a eta Easting (unit Earth)
41 s/a sigma xi + i * eta
43 y x Easting
45 x y Northing
47 k e Eccentricity
49 k^2 mu Elliptic function parameter
51 k'^2 mv Elliptic function complementary parameter
53 m k Scale
55 zeta zeta Complex longitude = Mercator = chi in paper
57 s sigma Complex GK = zeta in paper
59Minor alterations have been made in some of Lee's expressions in an attempt to
60control round-off. For example, C{atanh(sin(phi))} is replaced by C{asinh(tan(phi))}
61which maintains accuracy near C{phi = pi/2}. Such changes are noted in the code.
62'''
63# make sure int/int division yields float quotient, see .basics
64from __future__ import division as _; del _ # PYCHOK semicolon
66from pygeodesy.basics import map1, neg, neg_, _xinstanceof
67from pygeodesy.constants import EPS, EPS02, PI_2, PI_4, _K0_UTM, \
68 _1_EPS, _0_0, _0_1, _0_5, _1_0, _2_0, \
69 _3_0, _4_0, _90_0, isnear0, isnear90
70from pygeodesy.datums import _ellipsoidal_datum, _WGS84, _EWGS84
71# from pygeodesy.ellipsoids import _EWGS84 # from .datums
72from pygeodesy.elliptic import _ALL_LAZY, Elliptic
73# from pygeodesy.errors import _incompatible # from .named
74# from pygeodesy.fsums import Fsum # from .fmath
75from pygeodesy.fmath import cbrt, hypot, hypot1, hypot2, Fsum
76from pygeodesy.interns import _COMMASPACE_, _DASH_, _near_, _SPACE_, \
77 _spherical_
78from pygeodesy.karney import _copyBit, _diff182, _fix90, _norm2, _norm180, \
79 _tand, _unsigned2
80# from pygeodesy.lazily import _ALL_LAZY # from .elliptic
81from pygeodesy.named import callername, _incompatible, _NamedBase
82from pygeodesy.namedTuples import Forward4Tuple, Reverse4Tuple
83from pygeodesy.props import deprecated_method, deprecated_property_RO, \
84 Property_RO, property_RO, _update_all, \
85 property_doc_
86from pygeodesy.streprs import Fmt, pairs, unstr
87from pygeodesy.units import Degrees, Scalar_
88from pygeodesy.utily import atan1d, atan2d, _loneg, sincos2
89from pygeodesy.utm import _cmlon, _LLEB, _parseUTM5, _toBand, _toXtm8, \
90 _to7zBlldfn, Utm, UTMError
92from math import asinh, atan2, degrees, radians, sinh, sqrt
94__all__ = _ALL_LAZY.etm
95__version__ = '24.06.11'
97_OVERFLOW = _1_EPS**2 # about 2e+31
98_TAYTOL = pow(EPS, 0.6)
99_TAYTOL2 = _TAYTOL * _2_0
100_TOL_10 = EPS * _0_1
101_TRIPS = 21 # C++ 10
104class ETMError(UTMError):
105 '''Exact Transverse Mercator (ETM) parse, projection or other
106 L{Etm} issue or L{ExactTransverseMercator} conversion failure.
107 '''
108 pass
111class Etm(Utm):
112 '''Exact Transverse Mercator (ETM) coordinate, a sub-class of L{Utm},
113 a Universal Transverse Mercator (UTM) coordinate using the
114 L{ExactTransverseMercator} projection for highest accuracy.
116 @note: Conversion of (geodetic) lat- and longitudes to/from L{Etm}
117 coordinates is 3-4 times slower than to/from L{Utm}.
119 @see: Karney's U{Detailed Description<https://GeographicLib.SourceForge.io/
120 C++/doc/classGeographicLib_1_1TransverseMercatorExact.html#details>}.
121 '''
122 _Error = ETMError # see utm.UTMError
123 _exactTM = None
125 __init__ = Utm.__init__
126 '''New L{Etm} Exact Transverse Mercator coordinate, raising L{ETMError}s.
128 @see: L{Utm.__init__} for more information.
129 '''
131 @property_doc_(''' the ETM projection (L{ExactTransverseMercator}).''')
132 def exactTM(self):
133 '''Get the ETM projection (L{ExactTransverseMercator}).
134 '''
135 if self._exactTM is None:
136 self.exactTM = self.datum.exactTM # ExactTransverseMercator(datum=self.datum)
137 return self._exactTM
139 @exactTM.setter # PYCHOK setter!
140 def exactTM(self, exactTM):
141 '''Set the ETM projection (L{ExactTransverseMercator}).
143 @raise ETMError: The B{C{exacTM}}'s datum incompatible
144 with this ETM coordinate's C{datum}.
145 '''
146 _xinstanceof(ExactTransverseMercator, exactTM=exactTM)
148 E = self.datum.ellipsoid
149 if E != exactTM.ellipsoid: # may be None
150 raise ETMError(repr(exactTM), txt=_incompatible(repr(E)))
151 self._exactTM = exactTM
152 self._scale0 = exactTM.k0
154 def parse(self, strETM, **name):
155 '''Parse a string to a similar L{Etm} instance.
157 @arg strETM: The ETM coordinate (C{str}), see function L{parseETM5}.
158 @kwarg name: Optional C{B{name}=NN} (C{str}), overriding this name.
160 @return: The instance (L{Etm}).
162 @raise ETMError: Invalid B{C{strETM}}.
164 @see: Function L{pygeodesy.parseUPS5}, L{pygeodesy.parseUTM5} and
165 L{pygeodesy.parseUTMUPS5}.
166 '''
167 return parseETM5(strETM, datum=self.datum, Etm=self.classof,
168 name=self._name__(name))
170 @deprecated_method
171 def parseETM(self, strETM): # PYCHOK no cover
172 '''DEPRECATED, use method L{Etm.parse}.
173 '''
174 return self.parse(strETM)
176 def toLatLon(self, LatLon=None, unfalse=True, **unused): # PYCHOK expected
177 '''Convert this ETM coordinate to an (ellipsoidal) geodetic point.
179 @kwarg LatLon: Optional, ellipsoidal class to return the geodetic point
180 (C{LatLon}) or C{None}.
181 @kwarg unfalse: Unfalse B{C{easting}} and B{C{northing}} if C{falsed} (C{bool}).
183 @return: This ETM coordinate as (B{C{LatLon}}) or if C{B{LatLon} is None},
184 a L{LatLonDatum5Tuple}C{(lat, lon, datum, gamma, scale)}.
186 @raise ETMError: This ETM coordinate's C{exacTM} and this C{datum} are not
187 compatible or no convergence transforming to lat-/longitude.
189 @raise TypeError: Invalid or non-ellipsoidal B{C{LatLon}}.
190 '''
191 if not self._latlon or self._latlon._toLLEB_args != (unfalse, self.exactTM):
192 self._toLLEB(unfalse=unfalse)
193 return self._latlon5(LatLon)
195 def _toLLEB(self, unfalse=True, **unused): # PYCHOK signature
196 '''(INTERNAL) Compute (ellipsoidal) lat- and longitude.
197 '''
198 xTM, d = self.exactTM, self.datum
199 # double check that this and exactTM's ellipsoid match
200 if xTM._E != d.ellipsoid: # PYCHOK no cover
201 t = repr(d.ellipsoid)
202 raise ETMError(repr(xTM._E), txt=_incompatible(t))
204 e, n = self.eastingnorthing2(falsed=not unfalse)
205 lon0 = _cmlon(self.zone) if bool(unfalse) == self.falsed else None
206 lat, lon, g, k = xTM.reverse(e, n, lon0=lon0)
208 ll = _LLEB(lat, lon, datum=d, name=self.name) # utm._LLEB
209 self._latlon5args(ll, g, k, _toBand, unfalse, xTM)
211 def toUtm(self): # PYCHOK signature
212 '''Copy this ETM to a UTM coordinate.
214 @return: The UTM coordinate (L{Utm}).
215 '''
216 return self._xcopy2(Utm)
219class ExactTransverseMercator(_NamedBase):
220 '''Pure Python version of Karney's C++ class U{TransverseMercatorExact
221 <https://GeographicLib.SourceForge.io/C++/doc/TransverseMercatorExact_8cpp_source.html>},
222 a numerically exact transverse Mercator projection, further referred to as C{TMExact}.
223 '''
224 _datum = _WGS84 # Datum
225 _E = _EWGS84 # Ellipsoid
226 _extendp = False # use extended domain
227# _iteration = None # ._sigmaInv2 and ._zetaInv2
228 _k0 = _K0_UTM # central scale factor
229 _lat0 = _0_0 # central parallel
230 _lon0 = _0_0 # central meridian
231 _mu = _EWGS84.e2 # 1st eccentricity squared
232 _mv = _EWGS84.e21 # 1 - ._mu
233 _raiser = False # throw Error
234 _sigmaC = None # most recent _sigmaInv04 case C{int}
235 _zetaC = None # most recent _zetaInv04 case C{int}
237 def __init__(self, datum=_WGS84, lon0=0, k0=_K0_UTM, extendp=False, raiser=False, **name):
238 '''New L{ExactTransverseMercator} projection.
240 @kwarg datum: The I{non-spherical} datum or ellipsoid (L{Datum},
241 L{Ellipsoid}, L{Ellipsoid2} or L{a_f2Tuple}).
242 @kwarg lon0: Central meridian, default (C{degrees180}).
243 @kwarg k0: Central scale factor (C{float}).
244 @kwarg extendp: Use the I{extended} domain (C{bool}), I{standard} otherwise.
245 @kwarg raiser: If C{True}, throw an L{ETMError} for convergence failures (C{bool}).
246 @kwarg name: Optional C{B{name}=NN} for the projection (C{str}).
248 @raise ETMError: Near-spherical B{C{datum}} or C{ellipsoid} or invalid B{C{lon0}}
249 or B{C{k0}}.
251 @see: U{Constructor TransverseMercatorExact<https://GeographicLib.SourceForge.io/
252 C++/doc/classGeographicLib_1_1TransverseMercatorExact.html>} for more details,
253 especially on B{X{extendp}}.
255 @note: For all 255.5K U{TMcoords.dat<https://Zenodo.org/record/32470>} tests (with
256 C{0 <= lat <= 84} and C{0 <= lon}) the maximum error is C{5.2e-08 .forward}
257 (or 52 nano-meter) easting and northing and C{3.8e-13 .reverse} (or 0.38
258 pico-degrees) lat- and longitude (with Python 3.7.3+, 2.7.16+, PyPy6 3.5.3
259 and PyPy6 2.7.13, all in 64-bit on macOS 10.13.6 High Sierra C{x86_64} and
260 12.2 Monterey C{arm64} and C{"arm64_x86_64"}).
261 '''
262 if extendp:
263 self._extendp = True
264 if name:
265 self.name = name
266 if raiser:
267 self.raiser = True
269 TM = ExactTransverseMercator
270 if datum not in (TM._datum, TM._E, None):
271 self.datum = datum # invokes ._resets
272 if lon0 or lon0 != TM._lon0:
273 self.lon0 = lon0
274 if k0 is not TM._k0:
275 self.k0 = k0
277 @property_doc_(''' the datum (L{Datum}).''')
278 def datum(self):
279 '''Get the datum (L{Datum}) or C{None}.
280 '''
281 return self._datum
283 @datum.setter # PYCHOK setter!
284 def datum(self, datum):
285 '''Set the datum and ellipsoid (L{Datum}, L{Ellipsoid}, L{Ellipsoid2} or L{a_f2Tuple}).
287 @raise ETMError: Near-spherical B{C{datum}} or C{ellipsoid}.
288 '''
289 d = _ellipsoidal_datum(datum, name=self.name) # raiser=_datum_)
290 self._resets(d)
291 self._datum = d
293 @Property_RO
294 def _e(self):
295 '''(INTERNAL) Get and cache C{_e}.
296 '''
297 return self._E.e
299 @Property_RO
300 def _1_e_90(self): # PYCHOK no cover
301 '''(INTERNAL) Get and cache C{(1 - _e) * 90}.
302 '''
303 return (_1_0 - self._e) * _90_0
305 @property_RO
306 def ellipsoid(self):
307 '''Get the ellipsoid (L{Ellipsoid}).
308 '''
309 return self._E
311 @Property_RO
312 def _e_PI_2(self):
313 '''(INTERNAL) Get and cache C{_e * PI / 2}.
314 '''
315 return self._e * PI_2
317 @Property_RO
318 def _e_PI_4_(self):
319 '''(INTERNAL) Get and cache C{-_e * PI / 4}.
320 '''
321 return -self._e * PI_4
323 @Property_RO
324 def _1_e_PI_2(self):
325 '''(INTERNAL) Get and cache C{(1 - _e) * PI / 2}.
326 '''
327 return (_1_0 - self._e) * PI_2
329 @Property_RO
330 def _1_2e_PI_2(self):
331 '''(INTERNAL) Get and cache C{(1 - 2 * _e) * PI / 2}.
332 '''
333 return (_1_0 - self._e * _2_0) * PI_2
335 @property_RO
336 def equatoradius(self):
337 '''Get the C{ellipsoid}'s equatorial radius, semi-axis (C{meter}).
338 '''
339 return self._E.a
341 a = equatoradius
343 @Property_RO
344 def _e_TAYTOL(self):
345 '''(INTERNAL) Get and cache C{e * TAYTOL}.
346 '''
347 return self._e * _TAYTOL
349 @Property_RO
350 def _Eu(self):
351 '''(INTERNAL) Get and cache C{Elliptic(_mu)}.
352 '''
353 return Elliptic(self._mu)
355 @Property_RO
356 def _Eu_cE(self):
357 '''(INTERNAL) Get and cache C{_Eu.cE}.
358 '''
359 return self._Eu.cE
361 def _Eu_2cE_(self, xi):
362 '''(INTERNAL) Return C{_Eu.cE * 2 - B{xi}}.
363 '''
364 return self._Eu_cE * _2_0 - xi
366 @Property_RO
367 def _Eu_cE_4(self):
368 '''(INTERNAL) Get and cache C{_Eu.cE / 4}.
369 '''
370 return self._Eu_cE / _4_0
372 @Property_RO
373 def _Eu_cK(self):
374 '''(INTERNAL) Get and cache C{_Eu.cK}.
375 '''
376 return self._Eu.cK
378 @Property_RO
379 def _Eu_cK_cE(self):
380 '''(INTERNAL) Get and cache C{_Eu.cK / _Eu.cE}.
381 '''
382 return self._Eu_cK / self._Eu_cE
384 @Property_RO
385 def _Eu_2cK_PI(self):
386 '''(INTERNAL) Get and cache C{_Eu.cK * 2 / PI}.
387 '''
388 return self._Eu_cK / PI_2
390 @Property_RO
391 def _Ev(self):
392 '''(INTERNAL) Get and cache C{Elliptic(_mv)}.
393 '''
394 return Elliptic(self._mv)
396 @Property_RO
397 def _Ev_cK(self):
398 '''(INTERNAL) Get and cache C{_Ev.cK}.
399 '''
400 return self._Ev.cK
402 @Property_RO
403 def _Ev_cKE(self):
404 '''(INTERNAL) Get and cache C{_Ev.cKE}.
405 '''
406 return self._Ev.cKE
408 @Property_RO
409 def _Ev_3cKE_4(self):
410 '''(INTERNAL) Get and cache C{_Ev.cKE * 3 / 4}.
411 '''
412 return self._Ev_cKE * 0.75 # _0_75
414 @Property_RO
415 def _Ev_5cKE_4(self):
416 '''(INTERNAL) Get and cache C{_Ev.cKE * 5 / 4}.
417 '''
418 return self._Ev_cKE * 1.25 # _1_25
420 @Property_RO
421 def extendp(self):
422 '''Get the domain (C{bool}), I{extended} or I{standard}.
423 '''
424 return self._extendp
426 @property_RO
427 def flattening(self):
428 '''Get the C{ellipsoid}'s flattening (C{scalar}).
429 '''
430 return self._E.f
432 f = flattening
434 def forward(self, lat, lon, lon0=None, **name): # MCCABE 13
435 '''Forward projection, from geographic to transverse Mercator.
437 @arg lat: Latitude of point (C{degrees}).
438 @arg lon: Longitude of point (C{degrees}).
439 @kwarg lon0: Central meridian (C{degrees180}), overriding
440 the default if not C{None}.
441 @kwarg name: Optional C{B{name}=NN} (C{str}).
443 @return: L{Forward4Tuple}C{(easting, northing, gamma, scale)}.
445 @see: C{void TMExact::Forward(real lon0, real lat, real lon,
446 real &x, real &y,
447 real &gamma, real &k)}.
449 @raise ETMError: No convergence, thrown iff property
450 C{B{raiser}=True}.
451 '''
452 lat = _fix90(lat - self._lat0)
453 lon, _ = _diff182((self.lon0 if lon0 is None else lon0), lon)
454 if self.extendp:
455 backside = _lat = _lon = False
456 else: # enforce the parity
457 lat, _lat = _unsigned2(lat)
458 lon, _lon = _unsigned2(lon)
459 backside = lon > 90
460 if backside: # PYCHOK no cover
461 lon = _loneg(lon)
462 if lat == 0:
463 _lat = True
465 # u, v = coordinates for the Thompson TM, Lee 54
466 if lat == 90: # isnear90(lat)
467 u = self._Eu_cK
468 v = self._iteration = self._zetaC = 0
469 elif lat == 0 and lon == self._1_e_90: # PYCHOK no cover
470 u = self._iteration = self._zetaC = 0
471 v = self._Ev_cK
472 else: # tau = tan(phi), taup = sinh(psi)
473 tau, lam = _tand(lat), radians(lon)
474 u, v = self._zetaInv2(self._E.es_taupf(tau), lam)
476 sncndn6 = self._sncndn6(u, v)
477 y, x, _ = self._sigma3(v, *sncndn6)
478 g, k = (lon, self.k0) if isnear90(lat) else \
479 self._zetaScaled(sncndn6, ll=False)
481 if backside:
482 y, g = self._Eu_2cE_(y), _loneg(g)
483 y *= self._k0_a
484 x *= self._k0_a
485 if _lat:
486 y, g = neg_(y, g)
487 if _lon:
488 x, g = neg_(x, g)
489 return Forward4Tuple(x, y, g, k, iteration=self._iteration,
490 name=self._name__(name))
492 def _Inv03(self, psi, dlam, _3_mv_e): # (xi, deta, _3_mv)
493 '''(INTERNAL) Partial C{_zetaInv04} or C{_sigmaInv04}, Case 2
494 '''
495 # atan2(dlam-psi, psi+dlam) + 45d gives arg(zeta - zeta0) in
496 # range [-135, 225). Subtracting 180 (multiplier is negative)
497 # makes range [-315, 45). Multiplying by 1/3 (for cube root)
498 # gives range [-105, 15). In particular the range [-90, 180]
499 # in zeta space maps to [-90, 0] in w space as required.
500 a = atan2(dlam - psi, psi + dlam) / _3_0 - PI_4
501 s, c = sincos2(a)
502 h = hypot(psi, dlam)
503 r = cbrt(h * _3_mv_e)
504 u = r * c
505 v = r * s + self._Ev_cK
506 # Error using this guess is about 0.068 * rad^(5/3)
507 return u, v, h
509 @property_RO
510 def iteration(self):
511 '''Get the most recent C{ExactTransverseMercator.forward}
512 or C{ExactTransverseMercator.reverse} iteration number
513 (C{int}) or C{None} if not available/applicable.
514 '''
515 return self._iteration
517 @property_doc_(''' the central scale factor (C{float}).''')
518 def k0(self):
519 '''Get the central scale factor (C{float}), aka I{C{scale0}}.
520 '''
521 return self._k0 # aka scale0
523 @k0.setter # PYCHOK setter!
524 def k0(self, k0):
525 '''Set the central scale factor (C{float}), aka I{C{scale0}}.
527 @raise ETMError: Invalid B{C{k0}}.
528 '''
529 k0 = Scalar_(k0=k0, Error=ETMError, low=_TOL_10, high=_1_0)
530 if self._k0 != k0:
531 ExactTransverseMercator._k0_a._update(self) # redo ._k0_a
532 self._k0 = k0
534 @Property_RO
535 def _k0_a(self):
536 '''(INTERNAL) Get and cache C{k0 * equatoradius}.
537 '''
538 return self.k0 * self.equatoradius
540 @property_doc_(''' the central meridian (C{degrees180}).''')
541 def lon0(self):
542 '''Get the central meridian (C{degrees180}).
543 '''
544 return self._lon0
546 @lon0.setter # PYCHOK setter!
547 def lon0(self, lon0):
548 '''Set the central meridian (C{degrees180}).
550 @raise ETMError: Invalid B{C{lon0}}.
551 '''
552 self._lon0 = _norm180(Degrees(lon0=lon0, Error=ETMError))
554 @deprecated_property_RO
555 def majoradius(self): # PYCHOK no cover
556 '''DEPRECATED, use property C{equatoradius}.'''
557 return self.equatoradius
559 @Property_RO
560 def _1_mu_2(self):
561 '''(INTERNAL) Get and cache C{_mu / 2 + 1}.
562 '''
563 return self._mu * _0_5 + _1_0
565 @Property_RO
566 def _3_mv(self):
567 '''(INTERNAL) Get and cache C{3 / _mv}.
568 '''
569 return _3_0 / self._mv
571 @Property_RO
572 def _3_mv_e(self):
573 '''(INTERNAL) Get and cache C{3 / (_mv * _e)}.
574 '''
575 return _3_0 / (self._mv * self._e)
577 def _Newton2(self, taup, lam, u, v, C, *psi): # or (xi, eta, u, v)
578 '''(INTERNAL) Invert C{_zetaInv2} or C{_sigmaInv2} using Newton's method.
580 @return: 2-Tuple C{(u, v)}.
582 @raise ETMError: No convergence.
583 '''
584 sca1, tol2 = _1_0, _TOL_10
585 if psi: # _zetaInv2
586 sca1 = sca1 / hypot1(taup) # /= chokes PyChecker
587 tol2 = tol2 / max(psi[0], _1_0)**2
589 _zeta3 = self._zeta3
590 _zetaDwd2 = self._zetaDwd2
591 else: # _sigmaInv2
592 _zeta3 = self._sigma3
593 _zetaDwd2 = self._sigmaDwd2
595 d2, r = tol2, self.raiser
596 _U_2 = Fsum(u).fsum2f_
597 _V_2 = Fsum(v).fsum2f_
598 # min iterations 2, max 6 or 7, mean 3.9 or 4.0
599 _hy2 = hypot2
600 for i in range(1, _TRIPS): # GEOGRAPHICLIB_PANIC
601 sncndn6 = self._sncndn6(u, v)
602 du, dv = _zetaDwd2(*sncndn6)
603 T, L, _ = _zeta3(v, *sncndn6)
604 T = (taup - T) * sca1
605 L -= lam
606 u, dU = _U_2(T * du, L * dv)
607 v, dV = _V_2(T * dv, -L * du)
608 if d2 < tol2:
609 r = False
610 break
611 d2 = _hy2(dU, dV)
613 self._iteration = i
614 if r: # PYCHOK no cover
615 n = callername(up=2, underOK=True)
616 t = unstr(n, taup, lam, u, v, C=C)
617 raise ETMError(Fmt.no_convergence(d2, tol2), txt=t)
618 return u, v
620 @property_doc_(''' raise an L{ETMError} for convergence failures (C{bool}).''')
621 def raiser(self):
622 '''Get the error setting (C{bool}).
623 '''
624 return self._raiser
626 @raiser.setter # PYCHOK setter!
627 def raiser(self, raiser):
628 '''Set the error setting (C{bool}), if C{True} throw an L{ETMError}
629 for convergence failures.
630 '''
631 self._raiser = bool(raiser)
633 def reset(self, lat0, lon0):
634 '''Set the central parallel and meridian.
636 @arg lat0: Latitude of the central parallel (C{degrees90}).
637 @arg lon0: Longitude of the central parallel (C{degrees180}).
639 @return: 2-Tuple C{(lat0, lon0)} of the previous central
640 parallel and meridian.
642 @raise ETMError: Invalid B{C{lat0}} or B{C{lon0}}.
643 '''
644 t = self._lat0, self.lon0
645 self._lat0 = _fix90(Degrees(lat0=lat0, Error=ETMError))
646 self. lon0 = lon0
647 return t
649 def _resets(self, datum):
650 '''(INTERNAL) Set the ellipsoid and elliptic moduli.
652 @arg datum: Ellipsoidal datum (C{Datum}).
654 @raise ETMError: Near-spherical B{C{datum}} or C{ellipsoid}.
655 '''
656 E = datum.ellipsoid
657 mu = E.e2 # .eccentricity1st2
658 mv = E.e21 # _1_0 - mu
659 if isnear0(E.e) or isnear0(mu, eps0=EPS02) \
660 or isnear0(mv, eps0=EPS02): # or sqrt(mu) != E.e
661 raise ETMError(ellipsoid=E, txt=_near_(_spherical_))
663 if self._datum or self._E:
664 _i = ExactTransverseMercator.iteration._uname
665 _update_all(self, _i, '_sigmaC', '_zetaC') # _under
667 self._E = E
668 self._mu = mu
669 self._mv = mv
671 def reverse(self, x, y, lon0=None, **name):
672 '''Reverse projection, from Transverse Mercator to geographic.
674 @arg x: Easting of point (C{meters}).
675 @arg y: Northing of point (C{meters}).
676 @kwarg lon0: Optional central meridian (C{degrees180}),
677 overriding the default (C{iff not None}).
678 @kwarg name: Optional C{B{name}=NN} (C{str}).
680 @return: L{Reverse4Tuple}C{(lat, lon, gamma, scale)}.
682 @see: C{void TMExact::Reverse(real lon0, real x, real y,
683 real &lat, real &lon,
684 real &gamma, real &k)}
686 @raise ETMError: No convergence, thrown iff property
687 C{B{raiser}=True}.
688 '''
689 # undoes the steps in .forward.
690 xi = y / self._k0_a
691 eta = x / self._k0_a
692 if self.extendp:
693 backside = _lat = _lon = False
694 else: # enforce the parity
695 eta, _lon = _unsigned2(eta)
696 xi, _lat = _unsigned2(xi)
697 backside = xi > self._Eu_cE
698 if backside: # PYCHOK no cover
699 xi = self._Eu_2cE_(xi)
701 # u, v = coordinates for the Thompson TM, Lee 54
702 if xi or eta != self._Ev_cKE:
703 u, v = self._sigmaInv2(xi, eta)
704 else: # PYCHOK no cover
705 u = self._iteration = self._sigmaC = 0
706 v = self._Ev_cK
708 if v or u != self._Eu_cK:
709 g, k, lat, lon = self._zetaScaled(self._sncndn6(u, v))
710 else: # PYCHOK no cover
711 g, k, lat, lon = _0_0, self.k0, _90_0, _0_0
713 if backside: # PYCHOK no cover
714 lon, g = _loneg(lon), _loneg(g)
715 if _lat:
716 lat, g = neg_(lat, g)
717 if _lon:
718 lon, g = neg_(lon, g)
719 lat += self._lat0
720 lon += self._lon0 if lon0 is None else _norm180(lon0)
721 return Reverse4Tuple(lat, _norm180(lon), g, k, # _fix90(lat)
722 iteration=self._iteration,
723 name=self._name__(name))
725 def _scaled2(self, tau, d2, snu, cnu, dnu, snv, cnv, dnv):
726 '''(INTERNAL) C{scaled}.
728 @note: Argument B{C{d2}} is C{_mu * cnu**2 + _mv * cnv**2}
729 from C{._zeta3}.
731 @return: 2-Tuple C{(convergence, scale)}.
733 @see: C{void TMExact::Scale(real tau, real /*lam*/,
734 real snu, real cnu, real dnu,
735 real snv, real cnv, real dnv,
736 real &gamma, real &k)}.
737 '''
738 mu, mv = self._mu, self._mv
739 cnudnv = cnu * dnv
740 # Lee 55.12 -- negated for our sign convention. g gives
741 # the bearing (clockwise from true north) of grid north
742 g = atan2d(mv * cnv * snv * snu, cnudnv * dnu)
743 # Lee 55.13 with nu given by Lee 9.1 -- in sqrt change
744 # the numerator from (1 - snu^2 * dnv^2) to (_mv * snv^2
745 # + cnu^2 * dnv^2) to maintain accuracy near phi = 90
746 # and change the denomintor from (dnu^2 + dnv^2 - 1) to
747 # (_mu * cnu^2 + _mv * cnv^2) to maintain accuracy near
748 # phi = 0, lam = 90 * (1 - e). Similarly rewrite sqrt in
749 # 9.1 as _mv + _mu * c^2 instead of 1 - _mu * sin(phi)^2
750 if d2 > 0:
751 # originally: sec2 = 1 + tau**2 # sec(phi)^2
752 # d2 = (mu * cnu**2 + mv * cnv**2)
753 # q2 = (mv * snv**2 + cnudnv**2) / d2
754 # k = sqrt(mv + mu / sec2) * sqrt(sec2) * sqrt(q2)
755 # = sqrt(mv * sec2 + mu) * sqrt(q2)
756 # = sqrt(mv + mv * tau**2 + mu) * sqrt(q2)
757 k, q2 = _0_0, (mv * snv**2 + cnudnv**2)
758 if q2 > 0:
759 k2 = (tau**2 + _1_0) * mv + mu
760 if k2 > 0:
761 k = sqrt(k2) * sqrt(q2 / d2) * self.k0
762 else:
763 k = _OVERFLOW
764 return g, k
766 def _sigma3(self, v, snu, cnu, dnu, snv, cnv, dnv):
767 '''(INTERNAL) C{sigma}.
769 @return: 3-Tuple C{(xi, eta, d2)}.
771 @see: C{void TMExact::sigma(real /*u*/, real snu, real cnu, real dnu,
772 real v, real snv, real cnv, real dnv,
773 real &xi, real &eta)}.
775 @raise ETMError: No convergence.
776 '''
777 mu = self._mu * cnu
778 mv = self._mv * cnv
779 # Lee 55.4 writing
780 # dnu^2 + dnv^2 - 1 = _mu * cnu^2 + _mv * cnv^2
781 d2 = cnu * mu + cnv * mv
782 mu *= snu * dnu
783 mv *= snv * dnv
784 if d2 > 0: # /= chokes PyChecker
785 mu = mu / d2
786 mv = mv / d2
787 else:
788 mu, mv = map1(_overflow, mu, mv)
789 xi = self._Eu.fE(snu, cnu, dnu) - mu
790 v -= self._Ev.fE(snv, cnv, dnv) - mv
791 return xi, v, d2
793 def _sigmaDwd2(self, snu, cnu, dnu, snv, cnv, dnv):
794 '''(INTERNAL) C{sigmaDwd}.
796 @return: 2-Tuple C{(du, dv)}.
798 @see: C{void TMExact::dwdsigma(real /*u*/, real snu, real cnu, real dnu,
799 real /*v*/, real snv, real cnv, real dnv,
800 real &du, real &dv)}.
801 '''
802 mu = self._mu
803 snuv = snu * snv
804 # Reciprocal of 55.9: dw / ds = dn(w)^2/_mv,
805 # expanding complex dn(w) using A+S 16.21.4
806 d = (cnv**2 + snuv**2 * mu)**2 * self._mv
807 r = cnv * dnu * dnv
808 i = cnu * snuv * mu
809 du = (r**2 - i**2) / d # (r + i) * (r - i) / d
810 dv = neg(r * i * _2_0 / d)
811 return du, dv
813 def _sigmaInv2(self, xi, eta):
814 '''(INTERNAL) Invert C{sigma} using Newton's method.
816 @return: 2-Tuple C{(u, v)}.
818 @see: C{void TMExact::sigmainv(real xi, real eta,
819 real &u, real &v)}.
821 @raise ETMError: No convergence.
822 '''
823 u, v, t, self._sigmaC = self._sigmaInv04(xi, eta)
824 if not t:
825 u, v = self._Newton2(xi, eta, u, v, self._sigmaC)
826 return u, v
828 def _sigmaInv04(self, xi, eta):
829 '''(INTERNAL) Starting point for C{sigmaInv}.
831 @return: 4-Tuple C{(u, v, trip, Case)}.
833 @see: C{bool TMExact::sigmainv0(real xi, real eta,
834 real &u, real &v)}.
835 '''
836 t = False
837 d = eta - self._Ev_cKE
838 if eta > self._Ev_5cKE_4 or (xi < d and xi < -self._Eu_cE_4):
839 # sigma as a simple pole at
840 # w = w0 = Eu.K() + i * Ev.K()
841 # and sigma is approximated by
842 # sigma = (Eu.E() + i * Ev.KE()) + 1 / (w - w0)
843 u, v = _norm2(xi - self._Eu_cE, -d)
844 u += self._Eu_cK
845 v += self._Ev_cK
846 C = 1
848 elif (eta > self._Ev_3cKE_4 and xi < self._Eu_cE_4) or d > 0:
849 # At w = w0 = i * Ev.K(), we have
850 # sigma = sigma0 = i * Ev.KE()
851 # sigma' = sigma'' = 0
852 # including the next term in the Taylor series gives:
853 # sigma = sigma0 - _mv / 3 * (w - w0)^3
854 # When inverting this, we map arg(w - w0) = [-pi/2, -pi/6]
855 # to arg(sigma - sigma0) = [-pi/2, pi/2] mapping arg =
856 # [-pi/2, -pi/6] to [-pi/2, pi/2]
857 u, v, h = self._Inv03(xi, d, self._3_mv)
858 t = h < _TAYTOL2
859 C = 2
861 else: # use w = sigma * Eu.K/Eu.E (correct in limit _e -> 0)
862 u = v = self._Eu_cK_cE
863 u *= xi
864 v *= eta
865 C = 3
867 return u, v, t, C
869 def _sncndn6(self, u, v):
870 '''(INTERNAL) Get 6-tuple C{(snu, cnu, dnu, snv, cnv, dnv)}.
871 '''
872 # snu, cnu, dnu = self._Eu.sncndn(u)
873 # snv, cnv, dnv = self._Ev.sncndn(v)
874 return self._Eu.sncndn(u) + self._Ev.sncndn(v)
876 def toStr(self, joined=_COMMASPACE_, **kwds): # PYCHOK signature
877 '''Return a C{str} representation.
879 @kwarg joined: Separator to join the attribute strings
880 (C{str} or C{None} or C{NN} for non-joined).
881 @kwarg kwds: Optional, overriding keyword arguments.
882 '''
883 d = dict(datum=self.datum.name, lon0=self.lon0,
884 k0=self.k0, extendp=self.extendp)
885 if self.name:
886 d.update(name=self.name)
887 t = pairs(d, **kwds)
888 return joined.join(t) if joined else t
890 def _zeta3(self, unused, snu, cnu, dnu, snv, cnv, dnv): # _sigma3 signature
891 '''(INTERNAL) C{zeta}.
893 @return: 3-Tuple C{(taup, lambda, d2)}.
895 @see: C{void TMExact::zeta(real /*u*/, real snu, real cnu, real dnu,
896 real /*v*/, real snv, real cnv, real dnv,
897 real &taup, real &lam)}
898 '''
899 e, cnu2, mv = self._e, cnu**2, self._mv
900 # Overflow value like atan(overflow) = pi/2
901 t1 = t2 = _overflow(snu)
902 # Lee 54.17 but write
903 # atanh(snu * dnv) = asinh(snu * dnv / sqrt(cnu^2 + _mv * snu^2 * snv^2))
904 # atanh(_e * snu / dnv) = asinh(_e * snu / sqrt(_mu * cnu^2 + _mv * cnv^2))
905 d1 = cnu2 + mv * (snu * snv)**2
906 if d1 > EPS02: # _EPSmin
907 t1 = snu * dnv / sqrt(d1)
908 else:
909 d1 = 0
910 d2 = self._mu * cnu2 + mv * cnv**2
911 if d2 > EPS02: # _EPSmin
912 t2 = sinh(e * asinh(e * snu / sqrt(d2)))
913 else:
914 d2 = 0
915 # psi = asinh(t1) - asinh(t2)
916 # taup = sinh(psi)
917 taup = t1 * hypot1(t2) - t2 * hypot1(t1)
918 lam = (atan2(dnu * snv, cnu * cnv) -
919 atan2(cnu * snv * e, dnu * cnv) * e) if d1 and d2 else _0_0
920 return taup, lam, d2
922 def _zetaDwd2(self, snu, cnu, dnu, snv, cnv, dnv):
923 '''(INTERNAL) C{zetaDwd}.
925 @return: 2-Tuple C{(du, dv)}.
927 @see: C{void TMExact::dwdzeta(real /*u*/, real snu, real cnu, real dnu,
928 real /*v*/, real snv, real cnv, real dnv,
929 real &du, real &dv)}.
930 '''
931 cnu2 = cnu**2 * self._mu
932 cnv2 = cnv**2
933 dnuv = dnu * dnv
934 dnuv2 = dnuv**2
935 snuv = snu * snv
936 snuv2 = snuv**2 * self._mu
937 # Lee 54.21 but write (see A+S 16.21.4)
938 # (1 - dnu^2 * snv^2) = (cnv^2 + _mu * snu^2 * snv^2)
939 d = self._mv * (cnv2 + snuv2)**2 # max(d, EPS02)?
940 du = cnu * dnuv * (cnv2 - snuv2) / d
941 dv = cnv * snuv * (cnu2 + dnuv2) / d
942 return du, neg(dv)
944 def _zetaInv2(self, taup, lam):
945 '''(INTERNAL) Invert C{zeta} using Newton's method.
947 @return: 2-Tuple C{(u, v)}.
949 @see: C{void TMExact::zetainv(real taup, real lam,
950 real &u, real &v)}.
952 @raise ETMError: No convergence.
953 '''
954 psi = asinh(taup)
955 u, v, t, self._zetaC = self._zetaInv04(psi, lam)
956 if not t:
957 u, v = self._Newton2(taup, lam, u, v, self._zetaC, psi)
958 return u, v
960 def _zetaInv04(self, psi, lam):
961 '''(INTERNAL) Starting point for C{zetaInv}.
963 @return: 4-Tuple C{(u, v, trip, Case)}.
965 @see: C{bool TMExact::zetainv0(real psi, real lam, # radians
966 real &u, real &v)}.
967 '''
968 if lam > self._1_2e_PI_2:
969 d = lam - self._1_e_PI_2
970 if psi < d and psi < self._e_PI_4_: # PYCHOK no cover
971 # N.B. this branch is normally *not* taken because psi < 0
972 # is converted psi > 0 by .forward. There's a log singularity
973 # at w = w0 = Eu.K() + i * Ev.K(), corresponding to the south
974 # pole, where we have, approximately
975 # psi = _e + i * pi/2 - _e * atanh(cos(i * (w - w0)/(1 + _mu/2)))
976 # Inverting this gives:
977 e = self._e # eccentricity
978 s, c = sincos2((PI_2 - lam) / e)
979 h, r = sinh(_1_0 - psi / e), self._1_mu_2
980 u = self._Eu_cK - r * asinh(s / hypot(c, h))
981 v = self._Ev_cK - r * atan2(c, h)
982 return u, v, False, 1
984 elif psi < self._e_PI_2:
985 # At w = w0 = i * Ev.K(), we have
986 # zeta = zeta0 = i * (1 - _e) * pi/2
987 # zeta' = zeta'' = 0
988 # including the next term in the Taylor series gives:
989 # zeta = zeta0 - (_mv * _e) / 3 * (w - w0)^3
990 # When inverting this, we map arg(w - w0) = [-90, 0]
991 # to arg(zeta - zeta0) = [-90, 180]
992 u, v, h = self._Inv03(psi, d, self._3_mv_e)
993 return u, v, (h < self._e_TAYTOL), 2
995 # Use spherical TM, Lee 12.6 -- writing C{atanh(sin(lam) /
996 # cosh(psi)) = asinh(sin(lam) / hypot(cos(lam), sinh(psi)))}.
997 # This takes care of the log singularity at C{zeta = Eu.K()},
998 # corresponding to the north pole.
999 s, c = sincos2(lam)
1000 h, r = sinh(psi), self._Eu_2cK_PI
1001 # But scale to put 90, 0 on the right place
1002 u = r * atan2(h, c)
1003 v = r * asinh(s / hypot(h, c))
1004 return u, v, False, 3
1006 def _zetaScaled(self, sncndn6, ll=True):
1007 '''(INTERNAL) Recompute (T, L) from (u, v) to improve accuracy of Scale.
1009 @arg sncndn6: 6-Tuple C{(snu, cnu, dnu, snv, cnv, dnv)}.
1011 @return: 2-Tuple C{(g, k)} if not C{B{ll}} else
1012 4-tuple C{(g, k, lat, lon)}.
1013 '''
1014 t, lam, d2 = self._zeta3(None, *sncndn6)
1015 tau = self._E.es_tauf(t)
1016 g_k = self._scaled2(tau, d2, *sncndn6)
1017 if ll:
1018 g_k += atan1d(tau), degrees(lam)
1019 return g_k # or (g, k, lat, lon)
1022def _overflow(x):
1023 '''(INTERNAL) Like C{copysign0(OVERFLOW, B{x})}.
1024 '''
1025 return _copyBit(_OVERFLOW, x)
1028def parseETM5(strUTM, datum=_WGS84, Etm=Etm, falsed=True, **name):
1029 '''Parse a string representing a UTM coordinate, consisting
1030 of C{"zone[band] hemisphere easting northing"}.
1032 @arg strUTM: A UTM coordinate (C{str}).
1033 @kwarg datum: Optional datum to use (L{Datum}, L{Ellipsoid},
1034 L{Ellipsoid2} or L{a_f2Tuple}).
1035 @kwarg Etm: Optional class to return the UTM coordinate
1036 (L{Etm}) or C{None}.
1037 @kwarg falsed: Both easting and northing are C{falsed} (C{bool}).
1038 @kwarg name: Optional B{C{Etm}} C{B{name}=NN} (C{str}).
1040 @return: The UTM coordinate (B{C{Etm}}) or if C{B{Etm} is None}, a
1041 L{UtmUps5Tuple}C{(zone, hemipole, easting, northing, band)}
1042 with C{hemipole} is the hemisphere C{'N'|'S'}.
1044 @raise ETMError: Invalid B{C{strUTM}}.
1046 @raise TypeError: Invalid or near-spherical B{C{datum}}.
1047 '''
1048 r = _parseUTM5(strUTM, datum, Etm, falsed, Error=ETMError, **name)
1049 return r
1052def toEtm8(latlon, lon=None, datum=None, Etm=Etm, falsed=True,
1053 strict=True, zone=None, **name_cmoff):
1054 '''Convert a geodetic lat-/longitude to an ETM coordinate.
1056 @arg latlon: Latitude (C{degrees}) or an (ellipsoidal) geodetic
1057 C{LatLon} instance.
1058 @kwarg lon: Optional longitude (C{degrees}), required if B{C{latlon}}
1059 is C{degrees}, ignored otherwise.
1060 @kwarg datum: Optional datum for the ETM coordinate, overriding
1061 B{C{latlon}}'s datum (L{Datum}, L{Ellipsoid},
1062 L{Ellipsoid2} or L{a_f2Tuple}).
1063 @kwarg Etm: Optional class to return the ETM coordinate (L{Etm}) or C{None}.
1064 @kwarg falsed: False both easting and northing (C{bool}).
1065 @kwarg strict: Restrict B{C{lat}} to UTM ranges (C{bool}).
1066 @kwarg zone: Optional UTM zone to enforce (C{int} or C{str}).
1067 @kwarg name_cmoff: Optional B{C{Etm}} C{B{name}=NN} (C{str}) and DEPRECATED
1068 keyword argument C{B{cmoff}=True} to offset the longitude from
1069 the zone's central meridian (C{bool}), use B{C{falsed}} instead.
1071 @return: The ETM coordinate as B{C{Etm}} or if C{B{Etm} is None} or not B{C{falsed}},
1072 a L{UtmUps8Tuple}C{(zone, hemipole, easting, northing, band, datum, gamma,
1073 scale)}. The C{hemipole} is the C{'N'|'S'} hemisphere.
1075 @raise ETMError: No convergence transforming to ETM easting and northing.
1077 @raise ETMError: Invalid B{C{zone}} or near-spherical or incompatible B{C{datum}}
1078 or C{ellipsoid}.
1080 @raise RangeError: If B{C{lat}} outside the valid UTM bands or if B{C{lat}} or B{C{lon}}
1081 outside the valid range and L{rangerrors<pygeodesy.rangerrors>} is C{True}.
1083 @raise TypeError: Invalid or near-spherical B{C{datum}} or B{C{latlon}} not ellipsoidal.
1085 @raise ValueError: The B{C{lon}} value is missing or B{C{latlon}} is invalid.
1086 '''
1087 z, B, lat, lon, d, f, n = _to7zBlldfn(latlon, lon, datum,
1088 falsed, zone, strict,
1089 ETMError, **name_cmoff)
1090 lon0 = _cmlon(z) if f else None
1091 x, y, g, k = d.exactTM.forward(lat, lon, lon0=lon0)
1093 return _toXtm8(Etm, z, lat, x, y, B, d, g, k, f,
1094 n, latlon, d.exactTM, Error=ETMError)
1097if __name__ == '__main__': # MCCABE 13
1099 from pygeodesy import fstr, KTransverseMercator, printf
1100 from pygeodesy.internals import _usage
1101 from sys import argv, exit as _exit
1103 # mimick some of I{Karney}'s utility C{TransverseMercatorProj}
1104 _f = _r = _s = _t = False
1105 _p = -6
1106 _as = argv[1:]
1107 while _as and _as[0].startswith(_DASH_):
1108 _a = _as.pop(0)
1109 if len(_a) < 2:
1110 _exit('%s: option %r invalid' % (_usage(*argv), _a))
1111 elif '-forward'.startswith(_a):
1112 _f, _r = True, False
1113 elif '-reverse'.startswith(_a):
1114 _f, _r = False, True
1115 elif '-precision'.startswith(_a):
1116 _p = int(_as.pop(0))
1117 elif '-series'.startswith(_a):
1118 _s, _t = True, False
1119 elif _a == '-t':
1120 _s, _t = False, True
1121 elif '-help'.startswith(_a):
1122 _exit(_usage(argv[0], '[-s | -t ]',
1123 '[-p[recision] <ndigits>',
1124 '[-f[orward] <lat> <lon>',
1125 '|-r[everse] <easting> <northing>',
1126 '|<lat> <lon>]',
1127 '|-h[elp]'))
1128 else:
1129 _exit('%s: option %r not supported' % (_usage(*argv), _a))
1130 if len(_as) > 1:
1131 f2 = map1(float, *_as[:2])
1132 else:
1133 _exit('%s ...: incomplete' % (_usage(*argv),))
1135 if _s: # -series
1136 tm = KTransverseMercator()
1137 else:
1138 tm = ExactTransverseMercator(extendp=_t)
1140 if _f:
1141 t = tm.forward(*f2)
1142 elif _r:
1143 t = tm.reverse(*f2)
1144 else:
1145 t = tm.forward(*f2)
1146 printf('%s: %s', tm.classname, fstr(t, prec=_p, sep=_SPACE_))
1147 t = tm.reverse(t.easting, t.northing)
1148 printf('%s: %s', tm.classname, fstr(t, prec=_p, sep=_SPACE_))
1151# % python3 -m pygeodesy.etm -p 12 33.33 44.44
1152# ExactTransverseMercator: 4276926.11480390653 4727193.767015309073 28.375536563148 1.233325101778
1153# ExactTransverseMercator: 33.33 44.44 28.375536563148 1.233325101778
1155# % python3 -m pygeodesy.etm -s -p 12 33.33 44.44
1156# KTransverseMercator: 4276926.114803904667 4727193.767015310004 28.375536563148 1.233325101778
1157# KTransverseMercator: 33.33 44.44 28.375536563148 1.233325101778
1159# % echo 33.33 44.44 | .../bin/TransverseMercatorProj
1160# 4276926.114804 4727193.767015 28.375536563148 1.233325101778
1162# **) MIT License
1163#
1164# Copyright (C) 2016-2024 -- mrJean1 at Gmail -- All Rights Reserved.
1165#
1166# Permission is hereby granted, free of charge, to any person obtaining a
1167# copy of this software and associated documentation files (the "Software"),
1168# to deal in the Software without restriction, including without limitation
1169# the rights to use, copy, modify, merge, publish, distribute, sublicense,
1170# and/or sell copies of the Software, and to permit persons to whom the
1171# Software is furnished to do so, subject to the following conditions:
1172#
1173# The above copyright notice and this permission notice shall be included
1174# in all copies or substantial portions of the Software.
1175#
1176# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1177# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1178# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1179# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
1180# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1181# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
1182# OTHER DEALINGS IN THE SOFTWARE.