Coverage for pygeodesy/lcc.py: 96%
280 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-04-25 13:15 -0400
« prev ^ index » next coverage.py v7.6.1, created at 2025-04-25 13:15 -0400
2# -*- coding: utf-8 -*-
4u'''Lambert Conformal Conic (LCC) projection.
6Lambert conformal conic projection for 1- or 2-Standard Parallels classes L{Conic}, L{Conics} registry, L{LCCError}
7and position class L{Lcc}.
9See U{LCC<https://WikiPedia.org/wiki/Lambert_conformal_conic_projection>}, U{Lambert
10Conformal Conic to Geographic Transformation Formulae
11<https://www.Linz.govt.NZ/data/geodetic-system/coordinate-conversion/projection-conversions/lambert-conformal-conic-geographic>},
12U{Lambert Conformal Conic Projection<https://MathWorld.Wolfram.com/LambertConformalConicProjection.html>}
13and John P. Snyder U{'Map Projections - A Working Manual'<https://Pubs.USGS.gov/pp/1395/report.pdf>}, 1987, pp 107-109.
15@var Conics.Be08Lb: Conic(name='Be08Lb', lat0=50.797815, lon0=4.35921583, par1=49.8333339, par2=51.1666672, E0=649328, N0=665262, k0=1, SP=2, datum=Datum(name='GRS80', ellipsoid=Ellipsoids.GRS80, transform=Transforms.WGS84),
16@var Conics.Be72Lb: Conic(name='Be72Lb', lat0=90, lon0=4.3674867, par1=49.8333339, par2=51.1666672, E0=150000.013, N0=5400088.438, k0=1, SP=2, datum=Datum(name='NAD83', ellipsoid=Ellipsoids.GRS80, transform=Transforms.NAD83),
17@var Conics.Fr93Lb: Conic(name='Fr93Lb', lat0=46.5, lon0=3, par1=49, par2=44, E0=700000, N0=6600000, k0=1, SP=2, datum=Datum(name='WGS84', ellipsoid=Ellipsoids.WGS84, transform=Transforms.WGS84),
18@var Conics.MaNLb: Conic(name='MaNLb', lat0=33.3, lon0=-5.4, par1=31.73, par2=34.87, E0=500000, N0=300000, k0=1, SP=2, datum=Datum(name='NTF', ellipsoid=Ellipsoids.Clarke1880IGN, transform=Transforms.NTF),
19@var Conics.MxLb: Conic(name='MxLb', lat0=12, lon0=-102, par1=17.5, par2=29.5, E0=2500000, N0=0, k0=1, SP=2, datum=Datum(name='WGS84', ellipsoid=Ellipsoids.WGS84, transform=Transforms.WGS84),
20@var Conics.PyT_Lb: Conic(name='PyT_Lb', lat0=46.8, lon0=2.33722917, par1=45.8989389, par2=47.6960144, E0=600000, N0=200000, k0=1, SP=2, datum=Datum(name='NTF', ellipsoid=Ellipsoids.Clarke1880IGN, transform=Transforms.NTF),
21@var Conics.USA_Lb: Conic(name='USA_Lb', lat0=23, lon0=-96, par1=33, par2=45, E0=0, N0=0, k0=1, SP=2, datum=Datum(name='WGS84', ellipsoid=Ellipsoids.WGS84, transform=Transforms.WGS84),
22@var Conics.WRF_Lb: Conic(name='WRF_Lb', lat0=40, lon0=-97, par1=33, par2=45, E0=0, N0=0, k0=1, SP=2, datum=Datum(name='WGS84', ellipsoid=Ellipsoids.WGS84, transform=Transforms.WGS84)
23'''
24# make sure int/int division yields float quotient, see .basics
25from __future__ import division as _; del _ # PYCHOK semicolon
27from pygeodesy.basics import copysign0, _isin, _xinstanceof, _xsubclassof, \
28 typename
29from pygeodesy.constants import EPS, EPS02, PI_2, _float as _F, _0_0, _0_5, \
30 _1_0, _2_0, _90_0
31from pygeodesy.ellipsoidalBase import LatLonEllipsoidalBase as _LLEB
32from pygeodesy.datums import Datums, _ellipsoidal_datum
33from pygeodesy.errors import _IsnotError, _ValueError
34from pygeodesy.fmath import hypot, _ALL_LAZY
35# from pygeodesy.internals import typename # from .basics
36from pygeodesy.interns import NN, _COMMASPACE_, _DMAIN_, _ellipsoidal_, _GRS80_, \
37 _k0_, _lat0_, _lon0_, _m_, _NAD83_, _NTF_, _SPACE_, \
38 _WGS84_, _C_ # PYCHOK used!
39# from pygeodesy.lazily import _ALL_LAZY # from .fmath
40from pygeodesy.named import _lazyNamedEnumItem as _lazy, _name2__, _NamedBase, \
41 _NamedEnum, _NamedEnumItem, _xnamed
42from pygeodesy.namedTuples import EasNor3Tuple, LatLonDatum3Tuple, \
43 LatLon2Tuple, _LL4Tuple, PhiLam2Tuple
44from pygeodesy.props import deprecated_method, Property, Property_RO, _update_all
45from pygeodesy.streprs import Fmt, _fstrENH2, _xzipairs
46from pygeodesy.units import Easting, Height, _heigHt, Lamd, Northing, Phid, \
47 Scalar_
48from pygeodesy.utily import atan1, degrees90, degrees180, sincos2, tanPI_2_2
50from math import atan, fabs, log, radians, sin, sqrt
52__all__ = _ALL_LAZY.lcc
53__version__ = '25.04.14'
55_E0_ = 'E0'
56_N0_ = 'N0'
57_par1_ = 'par1'
58_par2_ = 'par2'
59_SP_ = 'SP'
62class Conic(_NamedEnumItem):
63 '''Lambert conformal conic projection (1- or 2-SP).
64 '''
65 _auth = NN # authorization (C{str})
66 _datum = None # datum (L{Datum})
67 _name = NN # Conic.__name__, set below
69 _e = _0_0 # ellipsoid excentricity (C{float})
70 _E0 = _0_0 # false easting (C{float})
71 _k0 = _1_0 # scale factor (C{float})
72 _N0 = _0_0 # false northing (C{float})
73 _SP = 0 # 1- or 2-SP (C{int})
75 _opt3 = _0_0 # optional, longitude (C{radians})
76 _par1 = _0_0 # 1st std parallel (C{radians})
77 _par2 = _0_0 # 2nd std parallel (C{radians})
78 _phi0 = _0_0 # origin lat (C{radians})
79 _lam0 = _0_0 # origin lon (C{radians})
81 _aF = _0_0 # precomputed F (C{float})
82 _n = _0_0 # precomputed n (C{float})
83 _1_n = _0_0 # precomputed 1 / n (C{float})
84 _r0 = _0_0 # precomputed rho0 (C{float})
86 def __init__(self, latlon0, par1, par2=None, E0=0, N0=0,
87 k0=1, opt3=0, auth=NN, **name):
88 '''New Lambert conformal conic projection.
90 @arg latlon0: Origin with (ellipsoidal) datum (C{LatLon}).
91 @arg par1: First standard parallel (C{degrees90}).
92 @kwarg par2: Optional, second standard parallel (C{degrees90}).
93 @kwarg E0: Optional, false easting (C{meter}).
94 @kwarg N0: Optional, false northing (C{meter}).
95 @kwarg k0: Optional scale factor (C{scalar}).
96 @kwarg opt3: Optional meridian (C{degrees180}).
97 @kwarg auth: Optional authentication authority (C{str}).
98 @kwarg name: Optional C{B{name}=NN} for the conic (C{str}).
100 @return: A Lambert projection (L{Conic}).
102 @raise TypeError: Non-ellipsoidal B{C{latlon0}}.
104 @raise ValueError: Invalid B{C{par1}}, B{C{par2}},
105 B{C{E0}}, B{C{N0}}, B{C{k0}}
106 or B{C{opt3}}.
107 '''
108 if latlon0 is not None:
109 _xinstanceof(_LLEB, latlon0=latlon0)
110 self._phi0, self._lam0 = latlon0.philam
112 self._par1 = Phid(par1=par1)
113 self._par2 = self._par1 if par2 is None else Phid(par2=par2)
115 if k0 != 1:
116 self._k0 = Scalar_(k0=k0)
117 if E0:
118 self._E0 = Northing(E0=E0, falsed=True)
119 if N0:
120 self._N0 = Easting(N0=N0, falsed=True)
121 if opt3:
122 self._opt3 = Lamd(opt3=opt3)
124 self.toDatum(latlon0.datum)._dup2(self)
125 self._register(Conics, name)
126 elif name:
127 self.name = name
128 if auth:
129 self._auth = str(auth)
131 @Property_RO
132 def auth(self):
133 '''Get the authentication authority (C{str}).
134 '''
135 return self._auth
137 @deprecated_method
138 def convertDatum(self, datum):
139 '''DEPRECATED, use method L{Conic.toDatum}.'''
140 return self.toDatum(datum)
142 @Property_RO
143 def datum(self):
144 '''Get the datum (L{Datum}).
145 '''
146 return self._datum
148 @Property_RO
149 def E0(self):
150 '''Get the false easting (C{meter}).
151 '''
152 return self._E0
154 @Property_RO
155 def k0(self):
156 '''Get scale factor (C{float}).
157 '''
158 return self._k0
160 @Property_RO
161 def lat0(self):
162 '''Get the origin latitude (C{degrees90}).
163 '''
164 return degrees90(self._phi0)
166 @Property_RO
167 def latlon0(self):
168 '''Get the central origin (L{LatLon2Tuple}C{(lat, lon)}).
169 '''
170 return LatLon2Tuple(self.lat0, self.lon0, name=self.name)
172 @Property_RO
173 def lam0(self):
174 '''Get the central meridian (C{radians}).
175 '''
176 return self._lam0
178 @Property_RO
179 def lon0(self):
180 '''Get the central meridian (C{degrees180}).
181 '''
182 return degrees180(self._lam0)
184 @Property_RO
185 def N0(self):
186 '''Get the false northing (C{meter}).
187 '''
188 return self._N0
190 @Property_RO
191 def name2(self):
192 '''Get the conic and datum names as "conic.datum" (C{str}).
193 '''
194 return self._DOT_(self.datum.name)
196 @Property_RO
197 def opt3(self):
198 '''Get the optional meridian (C{degrees180}).
199 '''
200 return degrees180(self._opt3)
202 @Property_RO
203 def par1(self):
204 '''Get the 1st standard parallel (C{degrees90}).
205 '''
206 return degrees90(self._par1)
208 @Property_RO
209 def par2(self):
210 '''Get the 2nd standard parallel (C{degrees90}).
211 '''
212 return degrees90(self._par2)
214 @Property_RO
215 def phi0(self):
216 '''Get the origin latitude (C{radians}).
217 '''
218 return self._phi0
220 @Property_RO
221 def philam0(self):
222 '''Get the central origin (L{PhiLam2Tuple}C{(phi, lam)}).
223 '''
224 return PhiLam2Tuple(self.phi0, self.lam0, name=self.name)
226 @Property_RO
227 def SP(self):
228 '''Get the number of standard parallels (C{int}).
229 '''
230 return self._SP
232 def toDatum(self, datum):
233 '''Convert this conic to the given datum.
235 @arg datum: Ellipsoidal datum to use (L{Datum}, L{Ellipsoid},
236 L{Ellipsoid2} or L{a_f2Tuple}).
238 @return: Converted conic, unregistered (L{Conic}).
240 @raise TypeError: Non-ellipsoidal B{C{datum}}.
241 '''
242 d = _ellipsoidal_datum(datum, name=self.name)
243 E = d.ellipsoid
244 if not E.isEllipsoidal:
245 raise _IsnotError(_ellipsoidal_, datum=datum)
247 c = self
248 if c._e != E.e or c._datum != d:
250 c = Conic(None, 0, name=self._name)
251 self._dup2(c)
252 c._datum = d
253 c._e = E.e
255 if fabs(c._par1 - c._par2) < EPS:
256 m1 = c._mdef(c._phi0)
257 t1 = c._tdef(c._phi0)
258 t0 = t1
259 k = 1 # _1_0
260 n = sin(c._phi0)
261 sp = 1
262 else:
263 m1 = c._mdef(c._par1)
264 m2 = c._mdef(c._par2)
265 t1 = c._tdef(c._par1)
266 t2 = c._tdef(c._par2)
267 t0 = c._tdef(c._phi0)
268 k = c._k0
269 n = (log(m1) - log(m2)) \
270 / (log(t1) - log(t2))
271 sp = 2
273 F = m1 / (n * pow(t1, n))
275 c._aF = k * E.a * F
276 c._n = n
277 c._1_n = _1_0 / n
278 c._r0 = c._rdef(t0)
279 c._SP = sp
281 return c
283 def toStr(self, prec=8, **name): # PYCHOK expected
284 '''Return this conic as a string.
286 @kwarg prec: Number of (decimal) digits, unstripped (C{int}).
287 @kwarg name: Overriding C{B{name}=NN} (C{str}) or C{None} to
288 exclude this conic's name.
290 @return: Conic attributes (C{str}).
291 '''
292 a = [_lat0_, _lon0_, _par1_, _par2_, _E0_, _N0_, _k0_, _SP_]
293 if self._SP == 1:
294 _ = a.pop(a.index(_par2_))
295 return self._instr(datum=self.datum, prec=prec, *a, **name)
297 def _dup2(self, c):
298 '''(INTERNAL) Copy this conic to C{c}.
300 @arg c: Duplicate (L{Conic}).
301 '''
302 _update_all(c)
304 c._auth = self._auth
305 c._datum = self._datum
307 c._e = self._e
308 c._E0 = self._E0
309 c._k0 = self._k0
310 c._N0 = self._N0
311 c._SP = self._SP
313 c._par1 = self._par1
314 c._par2 = self._par2
315 c._phi0 = self._phi0
316 c._lam0 = self._lam0
317 c._opt3 = self._opt3
319 c._aF = self._aF
320 c._n = self._n
321 c._1_n = self._1_n
322 c._r0 = self._r0
324 def _mdef(self, a):
325 '''(INTERNAL) Compute m(a).
326 '''
327 s, c = sincos2(a)
328 s = _1_0 - (s * self._e)**2
329 return (c / sqrt(s)) if s > EPS02 else _0_0
331 def _pdef(self, a):
332 '''(INTERNAL) Compute p(a).
333 '''
334 s = self._e * sin(a)
335 return pow((_1_0 - s) / (_1_0 + s), self._e * _0_5)
337 def _rdef(self, t):
338 '''(INTERNAL) Compute r(t).
339 '''
340 return self._aF * pow(t, self._n)
342 def _tdef(self, a):
343 '''(INTERNAL) Compute t(lat).
344 '''
345 return max(_0_0, tanPI_2_2(-a) / self._pdef(a))
347 def _xdef(self, t_x):
348 '''(INTERNAL) Compute x(t_x).
349 '''
350 return PI_2 - atan(t_x) * _2_0 # XXX + self._phi0
353Conic._name = typename(Conic)
356class Conics(_NamedEnum):
357 '''(INTERNAL) L{Conic} registry, I{must} be a sub-class
358 to accommodate the L{_LazyNamedEnumItem} properties.
359 '''
360 def _Lazy(self, lat, lon, datum_name, *args, **kwds):
361 '''(INTERNAL) Instantiate the L{Conic}.
362 '''
363 return Conic(_LLEB(lat, lon, datum=Datums.get(datum_name)), *args, **kwds)
365Conics = Conics(Conic) # PYCHOK singleton
366'''Some pre-defined L{Conic}s, all I{lazily} instantiated.'''
367Conics._assert( # <https://SpatialReference.org/ref/sr-org/...>
368# AsLb = _lazy('AsLb', _F(-14.2666667), _F(170), _NAD27_, _0_0, _0_0,
369# E0=_F(500000), N0=_0_0, auth='EPSG:2155'), # American Samoa ... SP=1 !
370 Be08Lb = _lazy('Be08Lb', _F(50.7978150), _F(4.359215833), _GRS80_, _F(49.8333339), _F(51.1666672),
371 E0=_F(649328.0), N0=_F(665262.0), auth='EPSG:9802'), # Belgium
372 Be72Lb = _lazy('Be72Lb', _90_0, _F(4.3674867), _NAD83_, _F(49.8333339), _F(51.1666672),
373 E0=_F(150000.013), N0=_F(5400088.438), auth='EPSG:31370'), # Belgium
374 Fr93Lb = _lazy('Fr93Lb', _F(46.5), _F(3), _WGS84_, _F(49), _F(44),
375 E0=_F(700000), N0=_F(6600000), auth='EPSG:2154'), # RFG93, France
376 MaNLb = _lazy('MaNLb', _F(33.3), _F(-5.4), _NTF_, _F(31.73), _F(34.87),
377 E0=_F(500000), N0=_F(300000)), # Marocco
378 MxLb = _lazy('MxLb', _F(12), _F(-102), _WGS84_, _F(17.5), _F(29.5),
379 E0=_F(2500000), N0=_0_0, auth='EPSG:2155'), # Mexico
380 PyT_Lb = _lazy('PyT_Lb', _F(46.8), _F(2.33722917), _NTF_, _F(45.89893890000052), _F(47.69601440000037),
381 E0=_F(600000), N0=_F(200000), auth='Test'), # France?
382 USA_Lb = _lazy('USA_Lb', _F(23), _F(-96), _WGS84_, _F(33), _F(45),
383 E0=_0_0, N0=_0_0), # Conterminous, contiguous USA?
384 WRF_Lb = _lazy('WRF_Lb', _F(40), _F(-97), _WGS84_, _F(33), _F(45),
385 E0=_0_0, N0=_0_0, auth='EPSG:4326') # World
386)
389class LCCError(_ValueError):
390 '''Lambert Conformal Conic C{LCC} or other L{Lcc} issue.
391 '''
392 pass
395class Lcc(_NamedBase):
396 '''Lambert conformal conic East-/Northing location.
397 '''
398 _conic = Conics.WRF_Lb # Lambert projection (L{Conic})
399 _easting = _0_0 # Easting (C{float})
400 _height = 0 # height (C{meter})
401 _northing = _0_0 # Northing (C{float})
403 def __init__(self, e, n, h=0, conic=Conics.WRF_Lb, **name):
404 '''New L{Lcc} Lamber conformal conic position.
406 @arg e: Easting (C{meter}).
407 @arg n: Northing (C{meter}).
408 @kwarg h: Optional height (C{meter}).
409 @kwarg conic: Optional, the conic projection (L{Conic}).
410 @kwarg name: Optional C{B{name}=NN} (C{str}).
412 @return: The Lambert location (L{Lcc}).
414 @raise LCCError: Invalid B{C{h}} or invalid or
415 negative B{C{e}} or B{C{n}}.
417 @raise TypeError: If B{C{conic}} is not L{Conic}.
418 '''
419 if not _isin(conic, None, Lcc._conic):
420 self.conic = conic
421 self._easting = Easting(e, falsed=conic.E0 > 0, Error=LCCError)
422 self._northing = Northing(n, falsed=conic.N0 > 0, Error=LCCError)
423 if h:
424 self._height = Height(h=h, Error=LCCError)
425 if name:
426 self.name = name
428 @Property
429 def conic(self):
430 '''Get the conic projection (L{Conic}).
431 '''
432 return self._conic
434 @conic.setter # PYCHOK setter!
435 def conic(self, conic):
436 '''Set the conic projection (L{Conic}).
438 @raise TypeError: Invalid B{C{conic}}.
439 '''
440 _xinstanceof(Conic, conic=conic)
441 if conic != self._conic:
442 _update_all(self)
443 self._conic = conic
445# def dup(self, name=NN, **e_n_h_conic): # PYCHOK signature
446# '''Duplicate this location with some attributes modified.
447#
448# @kwarg e_n_h_conic: Use keyword argument C{B{e}=...}, C{B{n}=...},
449# C{B{h}=...} and/or C{B{conic}=...} to override
450# the current C{easting}, C{northing} C{height}
451# or C{conic} projection, respectively.
452# '''
453# def _args_kwds(e=None, n=None, **kwds):
454# return (e, n), kwds
455#
456# kwds = _xkwds(e_n_h_conic, e=self.easting, n=self.northing,
457# h=self.height, conic=self.conic,
458# name=self._name__(name))
459# args, kwds = _args_kwds(**kwds)
460# return self.__class__(*args, **kwds) # .classof
462 @Property_RO
463 def easting(self):
464 '''Get the easting (C{meter}).
465 '''
466 return self._easting
468 @Property_RO
469 def height(self):
470 '''Get the height (C{meter}).
471 '''
472 return self._height
474 @Property_RO
475 def latlon(self):
476 '''Get the lat- and longitude in C{degrees} (L{LatLon2Tuple}).
477 '''
478 ll = self.toLatLon(LatLon=None, datum=None)
479 return LatLon2Tuple(ll.lat, ll.lon, name=self.name)
481 @Property_RO
482 def latlonheight(self):
483 '''Get the lat-, longitude and height (L{LatLon3Tuple}C{(lat, lon, height)}).
484 '''
485 return self.latlon.to3Tuple(self.height)
487 @Property_RO
488 def latlonheightdatum(self):
489 '''Get the lat-, longitude in C{degrees} with height and datum (L{LatLon4Tuple}C{(lat, lon, height, datum)}).
490 '''
491 return self.latlonheight.to4Tuple(self.conic.datum)
493 @Property_RO
494 def northing(self):
495 '''Get the northing (C{meter}).
496 '''
497 return self._northing
499 @Property_RO
500 def philam(self):
501 '''Get the lat- and longitude in C{radians} (L{PhiLam2Tuple}).
502 '''
503 return PhiLam2Tuple(radians(self.latlon.lat),
504 radians(self.latlon.lon), name=self.name)
506 @Property_RO
507 def philamheight(self):
508 '''Get the lat-, longitude in C{radians} and height (L{PhiLam3Tuple}C{(phi, lam, height)}).
509 '''
510 return self.philam.to3Tuple(self.height)
512 @Property_RO
513 def philamheightdatum(self):
514 '''Get the lat-, longitude in C{radians} with height and datum (L{PhiLam4Tuple}C{(phi, lam, height, datum)}).
515 '''
516 return self.philamheight.to4Tuple(self.datum)
518 @deprecated_method
519 def to3lld(self, datum=None): # PYCHOK no cover
520 '''DEPRECATED, use method C{toLatLon}.
522 @kwarg datum: Optional datum to use, otherwise use this
523 B{C{Lcc}}'s conic.datum (C{Datum}).
525 @return: A L{LatLonDatum3Tuple}C{(lat, lon, datum)}.
527 @raise TypeError: If B{C{datum}} is not ellipsoidal.
528 '''
529 if _isin(datum, None, self.conic.datum):
530 r = LatLonDatum3Tuple(self.latlon.lat,
531 self.latlon.lon,
532 self.conic.datum, name=self.name)
533 else:
534 r = self.toLatLon(LatLon=None, datum=datum)
535 r = LatLonDatum3Tuple(r.lat, r.lon, r.datum, name=r.name)
536 return r
538 def toLatLon(self, LatLon=None, datum=None, height=None, **LatLon_kwds):
539 '''Convert this L{Lcc} to an (ellipsoidal) geodetic point.
541 @kwarg LatLon: Optional, ellipsoidal class to return the geodetic
542 point (C{LatLon}) or C{None}.
543 @kwarg datum: Optional datum to use, otherwise use this B{C{Lcc}}'s
544 conic.datum (L{Datum}, L{Ellipsoid}, L{Ellipsoid2} or
545 L{a_f2Tuple}).
546 @kwarg height: Optional height for the point, overriding the default height
547 (C{meter}).
548 @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword arguments,
549 ignored if C{B{LatLon} is None}.
551 @return: The point (B{C{LatLon}}) or if C{B{LatLon} is None}, a
552 L{LatLon4Tuple}C{(lat, lon, height, datum)}.
554 @raise TypeError: If B{C{LatLon}} or B{C{datum}} is not ellipsoidal or
555 not valid.
556 '''
557 if LatLon:
558 _xsubclassof(_LLEB, LatLon=LatLon)
560 c = self.conic
561 if not _isin(datum, None, self.conic.datum):
562 c = c.toDatum(datum)
564 e = self.easting - c._E0
565 n = c._r0 - self.northing + c._N0
567 r_ = copysign0(hypot(e, n), c._n)
568 t_ = pow(r_ / c._aF, c._1_n)
570 x = c._xdef(t_) # XXX c._lam0
571 for self._iteration in range(10): # max 4 trips
572 p, x = x, c._xdef(t_ * c._pdef(x))
573 if fabs(x - p) < 1e-9: # XXX EPS too small?
574 break
575 lat = degrees90(x)
576 lon = degrees180((atan1(e, n) + c._opt3) * c._1_n + c._lam0)
578 h = _heigHt(self, height)
579 return _LL4Tuple(lat, lon, h, c.datum, LatLon, LatLon_kwds,
580 inst=self, name=self.name)
582 def toRepr(self, prec=0, fmt=Fmt.SQUARE, sep=_COMMASPACE_, m=_m_, C=False, **unused): # PYCHOK expected
583 '''Return a string representation of this L{Lcc} position.
585 @kwarg prec: Number of (decimal) digits, unstripped (C{int}).
586 @kwarg fmt: Enclosing backets format (C{str}).
587 @kwarg sep: Optional separator between name:values (C{str}).
588 @kwarg m: Optional unit of the height, default meter (C{str}).
589 @kwarg C: Optionally, include name of conic and datum (C{bool}).
591 @return: This Lcc as "[E:meter, N:meter, H:m, C:Conic.Datum]"
592 (C{str}).
593 '''
594 t, T = _fstrENH2(self, prec, m)
595 if C:
596 t += self.conic.name2,
597 T += _C_,
598 return _xzipairs(T, t, sep=sep, fmt=fmt)
600 def toStr(self, prec=0, sep=_SPACE_, m=_m_): # PYCHOK expected
601 '''Return a string representation of this L{Lcc} position.
603 @kwarg prec: Number of (decimal) digits, unstripped (C{int}).
604 @kwarg sep: Optional separator to join (C{str}) or C{None}
605 to return an unjoined C{tuple} of C{str}s.
606 @kwarg m: Optional height units, default C{meter} (C{str}).
608 @return: This Lcc as I{"easting nothing"} in C{meter} plus
609 I{" height"} suffixed with B{C{m}} if height is
610 non-zero (C{str}).
611 '''
612 t, _ = _fstrENH2(self, prec, m)
613 return t if sep is None else sep.join(t)
616def toLcc(latlon, conic=Conics.WRF_Lb, height=None, Lcc=Lcc,
617 **name_Lcc_kwds):
618 '''Convert an (ellipsoidal) geodetic point to a I{Lambert} location.
620 @arg latlon: Ellipsoidal point (C{LatLon}).
621 @kwarg conic: Optional Lambert projection to use (L{Conic}).
622 @kwarg height: Optional height for the point, overriding the
623 default height (C{meter}).
624 @kwarg Lcc: Class to return the I{Lambert} location (L{Lcc}).
625 @kwarg name_Lcc_kwds: Optional C{B{name}=NN} (C{str}) and optionally,
626 additional B{C{Lcc}} keyword arguments, ignored if B{C{Lcc}
627 is None}.
629 @return: The I{Lambert} location (L{Lcc}) or if C{B{Lcc} is None},
630 an L{EasNor3Tuple}C{(easting, northing, height)}.
632 @raise TypeError: If B{C{latlon}} is not ellipsoidal.
633 '''
634 _xinstanceof(_LLEB, latlon=latlon)
635 name, Lcc_kwds = _name2__(name_Lcc_kwds)
637 a, b = latlon.philam
638 c = conic.toDatum(latlon.datum)
640 t = c._n * (b - c._lam0) - c._opt3
641 st, ct = sincos2(t)
643 r = c._rdef(c._tdef(a))
644 e = c._E0 + r * st
645 n = c._N0 + c._r0 - r * ct
647 h = _heigHt(latlon, height)
648 r = EasNor3Tuple(e, n, h) if Lcc is None else \
649 Lcc(e, n, h=h, conic=c, **Lcc_kwds)
650 return _xnamed(r, name) if name else r
653if __name__ == _DMAIN_:
655 from pygeodesy.interns import _NL_, _NLATvar_
656 from pygeodesy.lazily import printf
658 # __doc__ of this file, force all into registery
659 t = _NL_ + Conics.toRepr(all=True, asorted=True)
660 printf(_NLATvar_.join(t.split(_NL_)))
662# **) MIT License
663#
664# Copyright (C) 2016-2025 -- mrJean1 at Gmail -- All Rights Reserved.
665#
666# Permission is hereby granted, free of charge, to any person obtaining a
667# copy of this software and associated documentation files (the "Software"),
668# to deal in the Software without restriction, including without limitation
669# the rights to use, copy, modify, merge, publish, distribute, sublicense,
670# and/or sell copies of the Software, and to permit persons to whom the
671# Software is furnished to do so, subject to the following conditions:
672#
673# The above copyright notice and this permission notice shall be included
674# in all copies or substantial portions of the Software.
675#
676# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
677# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
678# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
679# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
680# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
681# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
682# OTHER DEALINGS IN THE SOFTWARE.