1

2# -*- coding: utf-8 -*-

3

4 u'''Lambert Conformal Conic (LCC) projection.

5

6 Lambert conformal conic projection for 1- or 2-Standard Parallels classes L{Conic}, L{Conics} registry, L{LCCError}

7 and position class L{Lcc}.

8

9 See U{LCC<https://WikiPedia.org/wiki/Lambert_conformal_conic_projection>}, U{Lambert

10 Conformal Conic to Geographic Transformation Formulae

11<https://www.Linz.govt.NZ/data/geodetic-system/coordinate-conversion/projection-conversions/lambert-conformal-conic-geographic>},

12 U{Lambert Conformal Conic Projection<https://MathWorld.Wolfram.com/LambertConformalConicProjection.html>}

13 and John P. Snyder U{'Map Projections - A Working Manual'<https://Pubs.USGS.gov/pp/1395/report.pdf>}, 1987, pp 107-109.

14

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

25 from __future__ import division as _; del _ # PYCHOK semicolon

26

27 from pygeodesy.basics import copysign0, _xinstanceof, _xsubclassof

28 from pygeodesy.constants import EPS, EPS02, PI_2, _float as _F, _0_0, _0_5, \

29 _1_0, _2_0, _90_0

30 from pygeodesy.ellipsoidalBase import LatLonEllipsoidalBase as _LLEB

31 from pygeodesy.datums import Datums, _ellipsoidal_datum

32 from pygeodesy.errors import _IsnotError, _ValueError

33 from pygeodesy.fmath import hypot, _ALL_LAZY

34 from pygeodesy.interns import NN, _COMMASPACE_, _ellipsoidal_, _GRS80_, _k0_, \

35 _lat0_, _lon0_, _m_, _NAD83_, _NTF_, _SPACE_, \

36 _WGS84_, _C_ # PYCHOK used!

37# from pygeodesy.lazily import _ALL_LAZY # from .fmath

38 from pygeodesy.named import _lazyNamedEnumItem as _lazy, _name2__, _NamedBase, \

39 _NamedEnum, _NamedEnumItem, _xnamed

40 from pygeodesy.namedTuples import EasNor3Tuple, LatLonDatum3Tuple, \

41 LatLon2Tuple, _LL4Tuple, PhiLam2Tuple

42 from pygeodesy.props import deprecated_method, Property, Property_RO, _update_all

43 from pygeodesy.streprs import Fmt, _fstrENH2, _xzipairs

44 from pygeodesy.units import Easting, Height, _heigHt, Lamd, Northing, Phid, \

45 Scalar_

46 from pygeodesy.utily import atan1, degrees90, degrees180, sincos2, tanPI_2_2

47

48 from math import atan, fabs, log, radians, sin, sqrt

49

50__all__ = _ALL_LAZY.lcc

51__version__ = '24.06.24'

52

53_E0_ = 'E0'

54_N0_ = 'N0'

55_par1_ = 'par1'

56_par2_ = 'par2'

57_SP_ = 'SP'

58

59

60 class Conic(_NamedEnumItem):

61 '''Lambert conformal conic projection (1- or 2-SP).

62 '''

63 _auth = NN # authorization (C{str})

64 _datum = None # datum (L{Datum})

65 _name = NN # Conic.__name__, set below

66

67 _e = _0_0 # ellipsoid excentricity (C{float})

68 _E0 = _0_0 # false easting (C{float})

69 _k0 = _1_0 # scale factor (C{float})

70 _N0 = _0_0 # false northing (C{float})

71 _SP = 0 # 1- or 2-SP (C{int})

72

73 _opt3 = _0_0 # optional, longitude (C{radians})

74 _par1 = _0_0 # 1st std parallel (C{radians})

75 _par2 = _0_0 # 2nd std parallel (C{radians})

76 _phi0 = _0_0 # origin lat (C{radians})

77 _lam0 = _0_0 # origin lon (C{radians})

78

79 _aF = _0_0 # precomputed F (C{float})

80 _n = _0_0 # precomputed n (C{float})

81 _1_n = _0_0 # precomputed 1 / n (C{float})

82 _r0 = _0_0 # precomputed rho0 (C{float})

83

84 def __init__(self, latlon0, par1, par2=None, E0=0, N0=0,

85 k0=1, opt3=0, auth=NN, **name):

86 '''New Lambert conformal conic projection.

87

88 @arg latlon0: Origin with (ellipsoidal) datum (C{LatLon}).

89 @arg par1: First standard parallel (C{degrees90}).

90 @kwarg par2: Optional, second standard parallel (C{degrees90}).

91 @kwarg E0: Optional, false easting (C{meter}).

92 @kwarg N0: Optional, false northing (C{meter}).

93 @kwarg k0: Optional scale factor (C{scalar}).

94 @kwarg opt3: Optional meridian (C{degrees180}).

95 @kwarg auth: Optional authentication authority (C{str}).

96 @kwarg name: Optional C{B{name}=NN} for the conic (C{str}).

97

98 @return: A Lambert projection (L{Conic}).

99

100 @raise TypeError: Non-ellipsoidal B{C{latlon0}}.

101

102 @raise ValueError: Invalid B{C{par1}}, B{C{par2}},

103 B{C{E0}}, B{C{N0}}, B{C{k0}}

104 or B{C{opt3}}.

105 '''

106 if latlon0 is not None:

107 _xinstanceof(_LLEB, latlon0=latlon0)

108 self._phi0, self._lam0 = latlon0.philam

109

110 self._par1 = Phid(par1=par1)

111 self._par2 = self._par1 if par2 is None else Phid(par2=par2)

112

113 if k0 != 1:

114 self._k0 = Scalar_(k0=k0)

115 if E0:

116 self._E0 = Northing(E0=E0, falsed=True)

117 if N0:

118 self._N0 = Easting(N0=N0, falsed=True)

119 if opt3:

120 self._opt3 = Lamd(opt3=opt3)

121

122 self.toDatum(latlon0.datum)._dup2(self)

123 self._register(Conics, name)

124 elif name:

125 self.name = name

126 if auth:

127 self._auth = str(auth)

128

129 @Property_RO

130 def auth(self):

131 '''Get the authentication authority (C{str}).

132 '''

133 return self._auth

134

135 @deprecated_method

136 def convertDatum(self, datum):

137 '''DEPRECATED, use method L{Conic.toDatum}.'''

138 return self.toDatum(datum)

139

140 @Property_RO

141 def datum(self):

142 '''Get the datum (L{Datum}).

143 '''

144 return self._datum

145

146 @Property_RO

147 def E0(self):

148 '''Get the false easting (C{meter}).

149 '''

150 return self._E0

151

152 @Property_RO

153 def k0(self):

154 '''Get scale factor (C{float}).

155 '''

156 return self._k0

157

158 @Property_RO

159 def lat0(self):

160 '''Get the origin latitude (C{degrees90}).

161 '''

162 return degrees90(self._phi0)

163

164 @Property_RO

165 def latlon0(self):

166 '''Get the central origin (L{LatLon2Tuple}C{(lat, lon)}).

167 '''

168 return LatLon2Tuple(self.lat0, self.lon0, name=self.name)

169

170 @Property_RO

171 def lam0(self):

172 '''Get the central meridian (C{radians}).

173 '''

174 return self._lam0

175

176 @Property_RO

177 def lon0(self):

178 '''Get the central meridian (C{degrees180}).

179 '''

180 return degrees180(self._lam0)

181

182 @Property_RO

183 def N0(self):

184 '''Get the false northing (C{meter}).

185 '''

186 return self._N0

187

188 @Property_RO

189 def name2(self):

190 '''Get the conic and datum names as "conic.datum" (C{str}).

191 '''

192 return self._DOT_(self.datum.name)

193

194 @Property_RO

195 def opt3(self):

196 '''Get the optional meridian (C{degrees180}).

197 '''

198 return degrees180(self._opt3)

199

200 @Property_RO

201 def par1(self):

202 '''Get the 1st standard parallel (C{degrees90}).

203 '''

204 return degrees90(self._par1)

205

206 @Property_RO

207 def par2(self):

208 '''Get the 2nd standard parallel (C{degrees90}).

209 '''

210 return degrees90(self._par2)

211

212 @Property_RO

213 def phi0(self):

214 '''Get the origin latitude (C{radians}).

215 '''

216 return self._phi0

217

218 @Property_RO

219 def philam0(self):

220 '''Get the central origin (L{PhiLam2Tuple}C{(phi, lam)}).

221 '''

222 return PhiLam2Tuple(self.phi0, self.lam0, name=self.name)

223

224 @Property_RO

225 def SP(self):

226 '''Get the number of standard parallels (C{int}).

227 '''

228 return self._SP

229

230 def toDatum(self, datum):

231 '''Convert this conic to the given datum.

232

233 @arg datum: Ellipsoidal datum to use (L{Datum}, L{Ellipsoid},

234 L{Ellipsoid2} or L{a_f2Tuple}).

235

236 @return: Converted conic, unregistered (L{Conic}).

237

238 @raise TypeError: Non-ellipsoidal B{C{datum}}.

239 '''

240 d = _ellipsoidal_datum(datum, name=self.name)

241 E = d.ellipsoid

242 if not E.isEllipsoidal:

243 raise _IsnotError(_ellipsoidal_, datum=datum)

244

245 c = self

246 if c._e != E.e or c._datum != d:

247

248 c = Conic(None, 0, name=self._name)

249 self._dup2(c)

250 c._datum = d

251 c._e = E.e

252

253 if fabs(c._par1 - c._par2) < EPS:

254 m1 = c._mdef(c._phi0)

255 t1 = c._tdef(c._phi0)

256 t0 = t1

257 k = 1 # _1_0

258 n = sin(c._phi0)

259 sp = 1

260 else:

261 m1 = c._mdef(c._par1)

262 m2 = c._mdef(c._par2)

263 t1 = c._tdef(c._par1)

264 t2 = c._tdef(c._par2)

265 t0 = c._tdef(c._phi0)

266 k = c._k0

267 n = (log(m1) - log(m2)) \

268 / (log(t1) - log(t2))

269 sp = 2

270

271 F = m1 / (n * pow(t1, n))

272

273 c._aF = k * E.a * F

274 c._n = n

275 c._1_n = _1_0 / n

276 c._r0 = c._rdef(t0)

277 c._SP = sp

278

279 return c

280

281 def toStr(self, prec=8, **name): # PYCHOK expected

282 '''Return this conic as a string.

283

284 @kwarg prec: Number of (decimal) digits, unstripped (C{int}).

285 @kwarg name: Overriding C{B{name}=NN} (C{str}) or C{None} to

286 exclude this conic's name.

287

288 @return: Conic attributes (C{str}).

289 '''

290 a = [_lat0_, _lon0_, _par1_, _par2_, _E0_, _N0_, _k0_, _SP_]

291 if self._SP == 1:

292 _ = a.pop(a.index(_par2_))

293 return self._instr(datum=self.datum, prec=prec, *a, **name)

294

295 def _dup2(self, c):

296 '''(INTERNAL) Copy this conic to C{c}.

297

298 @arg c: Duplicate (L{Conic}).

299 '''

300 _update_all(c)

301

302 c._auth = self._auth

303 c._datum = self._datum

304

305 c._e = self._e

306 c._E0 = self._E0

307 c._k0 = self._k0

308 c._N0 = self._N0

309 c._SP = self._SP

310

311 c._par1 = self._par1

312 c._par2 = self._par2

313 c._phi0 = self._phi0

314 c._lam0 = self._lam0

315 c._opt3 = self._opt3

316

317 c._aF = self._aF

318 c._n = self._n

319 c._1_n = self._1_n

320 c._r0 = self._r0

321

322 def _mdef(self, a):

323 '''(INTERNAL) Compute m(a).

324 '''

325 s, c = sincos2(a)

326 s = _1_0 - (s * self._e)**2

327 return (c / sqrt(s)) if s > EPS02 else _0_0

328

329 def _pdef(self, a):

330 '''(INTERNAL) Compute p(a).

331 '''

332 s = self._e * sin(a)

333 return pow((_1_0 - s) / (_1_0 + s), self._e * _0_5)

334

335 def _rdef(self, t):

336 '''(INTERNAL) Compute r(t).

337 '''

338 return self._aF * pow(t, self._n)

339

340 def _tdef(self, a):

341 '''(INTERNAL) Compute t(lat).

342 '''

343 return max(_0_0, tanPI_2_2(-a) / self._pdef(a))

344

345 def _xdef(self, t_x):

346 '''(INTERNAL) Compute x(t_x).

347 '''

348 return PI_2 - atan(t_x) * _2_0 # XXX + self._phi0

349

350

351 Conic._name = Conic.__name__

352

353

354 class Conics(_NamedEnum):

355 '''(INTERNAL) L{Conic} registry, I{must} be a sub-class

356 to accommodate the L{_LazyNamedEnumItem} properties.

357 '''

358 def _Lazy(self, lat, lon, datum_name, *args, **kwds):

359 '''(INTERNAL) Instantiate the L{Conic}.

360 '''

361 return Conic(_LLEB(lat, lon, datum=Datums.get(datum_name)), *args, **kwds)

362

363 Conics = Conics(Conic) # PYCHOK singleton

364'''Some pre-defined L{Conic}s, all I{lazily} instantiated.'''

365 Conics._assert( # <https://SpatialReference.org/ref/sr-org/...>

366# AsLb = _lazy('AsLb', _F(-14.2666667), _F(170), _NAD27_, _0_0, _0_0,

367# E0=_F(500000), N0=_0_0, auth='EPSG:2155'), # American Samoa ... SP=1 !

368 Be08Lb = _lazy('Be08Lb', _F(50.7978150), _F(4.359215833), _GRS80_, _F(49.8333339), _F(51.1666672),

369 E0=_F(649328.0), N0=_F(665262.0), auth='EPSG:9802'), # Belgium

370 Be72Lb = _lazy('Be72Lb', _90_0, _F(4.3674867), _NAD83_, _F(49.8333339), _F(51.1666672),

371 E0=_F(150000.013), N0=_F(5400088.438), auth='EPSG:31370'), # Belgium

372 Fr93Lb = _lazy('Fr93Lb', _F(46.5), _F(3), _WGS84_, _F(49), _F(44),

373 E0=_F(700000), N0=_F(6600000), auth='EPSG:2154'), # RFG93, France

374 MaNLb = _lazy('MaNLb', _F(33.3), _F(-5.4), _NTF_, _F(31.73), _F(34.87),

375 E0=_F(500000), N0=_F(300000)), # Marocco

376 MxLb = _lazy('MxLb', _F(12), _F(-102), _WGS84_, _F(17.5), _F(29.5),

377 E0=_F(2500000), N0=_0_0, auth='EPSG:2155'), # Mexico

378 PyT_Lb = _lazy('PyT_Lb', _F(46.8), _F(2.33722917), _NTF_, _F(45.89893890000052), _F(47.69601440000037),

379 E0=_F(600000), N0=_F(200000), auth='Test'), # France?

380 USA_Lb = _lazy('USA_Lb', _F(23), _F(-96), _WGS84_, _F(33), _F(45),

381 E0=_0_0, N0=_0_0), # Conterminous, contiguous USA?

382 WRF_Lb = _lazy('WRF_Lb', _F(40), _F(-97), _WGS84_, _F(33), _F(45),

383 E0=_0_0, N0=_0_0, auth='EPSG:4326') # World

384)

385

386

387 class LCCError(_ValueError):

388 '''Lambert Conformal Conic C{LCC} or other L{Lcc} issue.

389 '''

390 pass

391

392

393 class Lcc(_NamedBase):

394 '''Lambert conformal conic East-/Northing location.

395 '''

396 _conic = Conics.WRF_Lb # Lambert projection (L{Conic})

397 _easting = _0_0 # Easting (C{float})

398 _height = 0 # height (C{meter})

399 _northing = _0_0 # Northing (C{float})

400

401 def __init__(self, e, n, h=0, conic=Conics.WRF_Lb, **name):

402 '''New L{Lcc} Lamber conformal conic position.

403

404 @arg e: Easting (C{meter}).

405 @arg n: Northing (C{meter}).

406 @kwarg h: Optional height (C{meter}).

407 @kwarg conic: Optional, the conic projection (L{Conic}).

408 @kwarg name: Optional C{B{name}=NN} (C{str}).

409

410 @return: The Lambert location (L{Lcc}).

411

412 @raise LCCError: Invalid B{C{h}} or invalid or

413 negative B{C{e}} or B{C{n}}.

414

415 @raise TypeError: If B{C{conic}} is not L{Conic}.

416 '''

417 if conic not in (None, Lcc._conic):

418 self.conic = conic

419 self._easting = Easting(e, falsed=conic.E0 > 0, Error=LCCError)

420 self._northing = Northing(n, falsed=conic.N0 > 0, Error=LCCError)

421 if h:

422 self._height = Height(h=h, Error=LCCError)

423 if name:

424 self.name = name

425

426 @Property

427 def conic(self):

428 '''Get the conic projection (L{Conic}).

429 '''

430 return self._conic

431

432 @conic.setter # PYCHOK setter!

433 def conic(self, conic):

434 '''Set the conic projection (L{Conic}).

435

436 @raise TypeError: Invalid B{C{conic}}.

437 '''

438 _xinstanceof(Conic, conic=conic)

439 if conic != self._conic:

440 _update_all(self)

441 self._conic = conic

442

443# def dup(self, name=NN, **e_n_h_conic): # PYCHOK signature

444# '''Duplicate this location with some attributes modified.

445#

446# @kwarg e_n_h_conic: Use keyword argument C{B{e}=...}, C{B{n}=...},

447# C{B{h}=...} and/or C{B{conic}=...} to override

448# the current C{easting}, C{northing} C{height}

449# or C{conic} projection, respectively.

450# '''

451# def _args_kwds(e=None, n=None, **kwds):

452# return (e, n), kwds

453#

454# kwds = _xkwds(e_n_h_conic, e=self.easting, n=self.northing,

455# h=self.height, conic=self.conic,

456# name=self._name__(name))

457# args, kwds = _args_kwds(**kwds)

458# return self.__class__(*args, **kwds) # .classof

459

460 @Property_RO

461 def easting(self):

462 '''Get the easting (C{meter}).

463 '''

464 return self._easting

465

466 @Property_RO

467 def height(self):

468 '''Get the height (C{meter}).

469 '''

470 return self._height

471

472 @Property_RO

473 def latlon(self):

474 '''Get the lat- and longitude in C{degrees} (L{LatLon2Tuple}).

475 '''

476 ll = self.toLatLon(LatLon=None, datum=None)

477 return LatLon2Tuple(ll.lat, ll.lon, name=self.name)

478

479 @Property_RO

480 def latlonheight(self):

481 '''Get the lat-, longitude and height (L{LatLon3Tuple}C{(lat, lon, height)}).

482 '''

483 return self.latlon.to3Tuple(self.height)

484

485 @Property_RO

486 def latlonheightdatum(self):

487 '''Get the lat-, longitude in C{degrees} with height and datum (L{LatLon4Tuple}C{(lat, lon, height, datum)}).

488 '''

489 return self.latlonheight.to4Tuple(self.conic.datum)

490

491 @Property_RO

492 def northing(self):

493 '''Get the northing (C{meter}).

494 '''

495 return self._northing

496

497 @Property_RO

498 def philam(self):

499 '''Get the lat- and longitude in C{radians} (L{PhiLam2Tuple}).

500 '''

501 return PhiLam2Tuple(radians(self.latlon.lat),

502 radians(self.latlon.lon), name=self.name)

503

504 @Property_RO

505 def philamheight(self):

506 '''Get the lat-, longitude in C{radians} and height (L{PhiLam3Tuple}C{(phi, lam, height)}).

507 '''

508 return self.philam.to3Tuple(self.height)

509

510 @Property_RO

511 def philamheightdatum(self):

512 '''Get the lat-, longitude in C{radians} with height and datum (L{PhiLam4Tuple}C{(phi, lam, height, datum)}).

513 '''

514 return self.philamheight.to4Tuple(self.datum)

515

516 @deprecated_method

517 def to3lld(self, datum=None): # PYCHOK no cover

518 '''DEPRECATED, use method C{toLatLon}.

519

520 @kwarg datum: Optional datum to use, otherwise use this

521 B{C{Lcc}}'s conic.datum (C{Datum}).

522

523 @return: A L{LatLonDatum3Tuple}C{(lat, lon, datum)}.

524

525 @raise TypeError: If B{C{datum}} is not ellipsoidal.

526 '''

527 if datum in (None, self.conic.datum):

528 r = LatLonDatum3Tuple(self.latlon.lat,

529 self.latlon.lon,

530 self.conic.datum, name=self.name)

531 else:

532 r = self.toLatLon(LatLon=None, datum=datum)

533 r = LatLonDatum3Tuple(r.lat, r.lon, r.datum, name=r.name)

534 return r

535

536 def toLatLon(self, LatLon=None, datum=None, height=None, **LatLon_kwds):

537 '''Convert this L{Lcc} to an (ellipsoidal) geodetic point.

538

539 @kwarg LatLon: Optional, ellipsoidal class to return the geodetic

540 point (C{LatLon}) or C{None}.

541 @kwarg datum: Optional datum to use, otherwise use this B{C{Lcc}}'s

542 conic.datum (L{Datum}, L{Ellipsoid}, L{Ellipsoid2} or

543 L{a_f2Tuple}).

544 @kwarg height: Optional height for the point, overriding the default height

545 (C{meter}).

546 @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword arguments,

547 ignored if C{B{LatLon} is None}.

548

549 @return: The point (B{C{LatLon}}) or if C{B{LatLon} is None}, a

550 L{LatLon4Tuple}C{(lat, lon, height, datum)}.

551

552 @raise TypeError: If B{C{LatLon}} or B{C{datum}} is not ellipsoidal or

553 not valid.

554 '''

555 if LatLon:

556 _xsubclassof(_LLEB, LatLon=LatLon)

557

558 c = self.conic

559 if datum not in (None, self.conic.datum):

560 c = c.toDatum(datum)

561

562 e = self.easting - c._E0

563 n = c._r0 - self.northing + c._N0

564

565 r_ = copysign0(hypot(e, n), c._n)

566 t_ = pow(r_ / c._aF, c._1_n)

567

568 x = c._xdef(t_) # XXX c._lam0

569 for self._iteration in range(10): # max 4 trips

570 p, x = x, c._xdef(t_ * c._pdef(x))

571 if fabs(x - p) < 1e-9: # XXX EPS too small?

572 break

573 lat = degrees90(x)

574 lon = degrees180((atan1(e, n) + c._opt3) * c._1_n + c._lam0)

575

576 h = _heigHt(self, height)

577 return _LL4Tuple(lat, lon, h, c.datum, LatLon, LatLon_kwds,

578 inst=self, name=self.name)

579

580 def toRepr(self, prec=0, fmt=Fmt.SQUARE, sep=_COMMASPACE_, m=_m_, C=False, **unused): # PYCHOK expected

581 '''Return a string representation of this L{Lcc} position.

582

583 @kwarg prec: Number of (decimal) digits, unstripped (C{int}).

584 @kwarg fmt: Enclosing backets format (C{str}).

585 @kwarg sep: Optional separator between name:values (C{str}).

586 @kwarg m: Optional unit of the height, default meter (C{str}).

587 @kwarg C: Optionally, include name of conic and datum (C{bool}).

588

589 @return: This Lcc as "[E:meter, N:meter, H:m, C:Conic.Datum]"

590 (C{str}).

591 '''

592 t, T = _fstrENH2(self, prec, m)

593 if C:

594 t += self.conic.name2,

595 T += _C_,

596 return _xzipairs(T, t, sep=sep, fmt=fmt)

597

598 def toStr(self, prec=0, sep=_SPACE_, m=_m_): # PYCHOK expected

599 '''Return a string representation of this L{Lcc} position.

600

601 @kwarg prec: Number of (decimal) digits, unstripped (C{int}).

602 @kwarg sep: Optional separator to join (C{str}) or C{None}

603 to return an unjoined C{tuple} of C{str}s.

604 @kwarg m: Optional height units, default C{meter} (C{str}).

605

606 @return: This Lcc as I{"easting nothing"} in C{meter} plus

607 I{" height"} suffixed with B{C{m}} if height is

608 non-zero (C{str}).

609 '''

610 t, _ = _fstrENH2(self, prec, m)

611 return t if sep is None else sep.join(t)

612

613

614 def toLcc(latlon, conic=Conics.WRF_Lb, height=None, Lcc=Lcc,

615 **name_Lcc_kwds):

616 '''Convert an (ellipsoidal) geodetic point to a I{Lambert} location.

617

618 @arg latlon: Ellipsoidal point (C{LatLon}).

619 @kwarg conic: Optional Lambert projection to use (L{Conic}).

620 @kwarg height: Optional height for the point, overriding the

621 default height (C{meter}).

622 @kwarg Lcc: Class to return the I{Lambert} location (L{Lcc}).

623 @kwarg name_Lcc_kwds: Optional C{B{name}=NN} (C{str}) and optional,

624 additional B{C{Lcc}} keyword arguments, ignored if

625 B{C{Lcc} is None}.

626

627 @return: The I{Lambert} location (L{Lcc}) or if C{B{Lcc} is None},

628 an L{EasNor3Tuple}C{(easting, northing, height)}.

629

630 @raise TypeError: If B{C{latlon}} is not ellipsoidal.

631 '''

632 _xinstanceof(_LLEB, latlon=latlon)

633 name, Lcc_kwds = _name2__(name_Lcc_kwds)

634

635 a, b = latlon.philam

636 c = conic.toDatum(latlon.datum)

637

638 t = c._n * (b - c._lam0) - c._opt3

639 st, ct = sincos2(t)

640

641 r = c._rdef(c._tdef(a))

642 e = c._E0 + r * st

643 n = c._N0 + c._r0 - r * ct

644

645 h = _heigHt(latlon, height)

646 r = EasNor3Tuple(e, n, h) if Lcc is None else \

647 Lcc(e, n, h=h, conic=c, **Lcc_kwds)

648 return _xnamed(r, name) if name else r

649

650

651 if __name__ == '__main__':

652

653 from pygeodesy.interns import _NL_, _NLATvar_

654 from pygeodesy.lazily import printf

655

656 # __doc__ of this file, force all into registery

657 t = _NL_ + Conics.toRepr(all=True, asorted=True)

658 printf(_NLATvar_.join(t.split(_NL_)))

659

660# **) MIT License

661#

662# Copyright (C) 2016-2024 -- mrJean1 at Gmail -- All Rights Reserved.

663#

664# Permission is hereby granted, free of charge, to any person obtaining a

665# copy of this software and associated documentation files (the "Software"),

666# to deal in the Software without restriction, including without limitation

667# the rights to use, copy, modify, merge, publish, distribute, sublicense,

668# and/or sell copies of the Software, and to permit persons to whom the

669# Software is furnished to do so, subject to the following conditions:

670#

671# The above copyright notice and this permission notice shall be included

672# in all copies or substantial portions of the Software.

673#

674# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS

675# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

676# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL

677# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR

678# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,

679# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR

680# OTHER DEALINGS IN THE SOFTWARE.