pygeodesy 24.3.24__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. PyGeodesy-24.3.24.dist-info/METADATA +272 -0
  2. PyGeodesy-24.3.24.dist-info/RECORD +115 -0
  3. PyGeodesy-24.3.24.dist-info/WHEEL +6 -0
  4. PyGeodesy-24.3.24.dist-info/top_level.txt +1 -0
  5. pygeodesy/LICENSE +21 -0
  6. pygeodesy/__init__.py +615 -0
  7. pygeodesy/__main__.py +103 -0
  8. pygeodesy/albers.py +867 -0
  9. pygeodesy/auxilats/_CX_4.py +218 -0
  10. pygeodesy/auxilats/_CX_6.py +314 -0
  11. pygeodesy/auxilats/_CX_8.py +475 -0
  12. pygeodesy/auxilats/__init__.py +54 -0
  13. pygeodesy/auxilats/__main__.py +86 -0
  14. pygeodesy/auxilats/auxAngle.py +548 -0
  15. pygeodesy/auxilats/auxDLat.py +302 -0
  16. pygeodesy/auxilats/auxDST.py +296 -0
  17. pygeodesy/auxilats/auxLat.py +848 -0
  18. pygeodesy/auxilats/auxily.py +272 -0
  19. pygeodesy/azimuthal.py +1150 -0
  20. pygeodesy/basics.py +892 -0
  21. pygeodesy/booleans.py +2031 -0
  22. pygeodesy/cartesianBase.py +1062 -0
  23. pygeodesy/clipy.py +704 -0
  24. pygeodesy/constants.py +516 -0
  25. pygeodesy/css.py +660 -0
  26. pygeodesy/datums.py +752 -0
  27. pygeodesy/deprecated/__init__.py +61 -0
  28. pygeodesy/deprecated/bases.py +40 -0
  29. pygeodesy/deprecated/classes.py +262 -0
  30. pygeodesy/deprecated/consterns.py +54 -0
  31. pygeodesy/deprecated/datum.py +40 -0
  32. pygeodesy/deprecated/functions.py +375 -0
  33. pygeodesy/deprecated/nvector.py +48 -0
  34. pygeodesy/deprecated/rhumbBase.py +32 -0
  35. pygeodesy/deprecated/rhumbaux.py +33 -0
  36. pygeodesy/deprecated/rhumbsolve.py +33 -0
  37. pygeodesy/deprecated/rhumbx.py +33 -0
  38. pygeodesy/dms.py +986 -0
  39. pygeodesy/ecef.py +1348 -0
  40. pygeodesy/elevations.py +279 -0
  41. pygeodesy/ellipsoidalBase.py +1224 -0
  42. pygeodesy/ellipsoidalBaseDI.py +913 -0
  43. pygeodesy/ellipsoidalExact.py +343 -0
  44. pygeodesy/ellipsoidalGeodSolve.py +343 -0
  45. pygeodesy/ellipsoidalKarney.py +403 -0
  46. pygeodesy/ellipsoidalNvector.py +685 -0
  47. pygeodesy/ellipsoidalVincenty.py +590 -0
  48. pygeodesy/ellipsoids.py +2476 -0
  49. pygeodesy/elliptic.py +1198 -0
  50. pygeodesy/epsg.py +243 -0
  51. pygeodesy/errors.py +804 -0
  52. pygeodesy/etm.py +1190 -0
  53. pygeodesy/fmath.py +1013 -0
  54. pygeodesy/formy.py +1818 -0
  55. pygeodesy/frechet.py +865 -0
  56. pygeodesy/fstats.py +760 -0
  57. pygeodesy/fsums.py +1898 -0
  58. pygeodesy/gars.py +358 -0
  59. pygeodesy/geodesicw.py +581 -0
  60. pygeodesy/geodesicx/_C4_24.py +1699 -0
  61. pygeodesy/geodesicx/_C4_27.py +2395 -0
  62. pygeodesy/geodesicx/_C4_30.py +3301 -0
  63. pygeodesy/geodesicx/__init__.py +48 -0
  64. pygeodesy/geodesicx/__main__.py +91 -0
  65. pygeodesy/geodesicx/gx.py +1382 -0
  66. pygeodesy/geodesicx/gxarea.py +535 -0
  67. pygeodesy/geodesicx/gxbases.py +154 -0
  68. pygeodesy/geodesicx/gxline.py +669 -0
  69. pygeodesy/geodsolve.py +426 -0
  70. pygeodesy/geohash.py +914 -0
  71. pygeodesy/geoids.py +1884 -0
  72. pygeodesy/hausdorff.py +892 -0
  73. pygeodesy/heights.py +1155 -0
  74. pygeodesy/interns.py +687 -0
  75. pygeodesy/iters.py +545 -0
  76. pygeodesy/karney.py +919 -0
  77. pygeodesy/ktm.py +633 -0
  78. pygeodesy/latlonBase.py +1766 -0
  79. pygeodesy/lazily.py +960 -0
  80. pygeodesy/lcc.py +684 -0
  81. pygeodesy/ltp.py +1107 -0
  82. pygeodesy/ltpTuples.py +1563 -0
  83. pygeodesy/mgrs.py +721 -0
  84. pygeodesy/named.py +1324 -0
  85. pygeodesy/namedTuples.py +683 -0
  86. pygeodesy/nvectorBase.py +695 -0
  87. pygeodesy/osgr.py +781 -0
  88. pygeodesy/points.py +1686 -0
  89. pygeodesy/props.py +628 -0
  90. pygeodesy/resections.py +1048 -0
  91. pygeodesy/rhumb/__init__.py +46 -0
  92. pygeodesy/rhumb/aux_.py +397 -0
  93. pygeodesy/rhumb/bases.py +1148 -0
  94. pygeodesy/rhumb/ekx.py +563 -0
  95. pygeodesy/rhumb/solve.py +572 -0
  96. pygeodesy/simplify.py +647 -0
  97. pygeodesy/solveBase.py +472 -0
  98. pygeodesy/sphericalBase.py +724 -0
  99. pygeodesy/sphericalNvector.py +1264 -0
  100. pygeodesy/sphericalTrigonometry.py +1447 -0
  101. pygeodesy/streprs.py +627 -0
  102. pygeodesy/trf.py +2079 -0
  103. pygeodesy/triaxials.py +1484 -0
  104. pygeodesy/units.py +969 -0
  105. pygeodesy/unitsBase.py +349 -0
  106. pygeodesy/ups.py +538 -0
  107. pygeodesy/utily.py +1231 -0
  108. pygeodesy/utm.py +762 -0
  109. pygeodesy/utmups.py +318 -0
  110. pygeodesy/utmupsBase.py +517 -0
  111. pygeodesy/vector2d.py +785 -0
  112. pygeodesy/vector3d.py +968 -0
  113. pygeodesy/vector3dBase.py +1049 -0
  114. pygeodesy/webmercator.py +383 -0
  115. pygeodesy/wgrs.py +439 -0
@@ -0,0 +1,590 @@
1
+
2
+ # -*- coding: utf-8 -*-
3
+
4
+ u'''Ellipsoidal, I{Vincenty}-based geodesy.
5
+
6
+ I{Thaddeus Vincenty}'s geodetic (lat-/longitude) L{LatLon}, geocentric
7
+ (ECEF) L{Cartesian} and L{VincentyError} classes and functions L{areaOf},
8
+ L{intersections2}, L{nearestOn} and L{perimeterOf}.
9
+
10
+ Pure Python implementation of geodesy tools for ellipsoidal earth models,
11
+ transcoded from JavaScript originals by I{(C) Chris Veness 2005-2016}
12
+ and published under the same MIT Licence**, see U{Vincenty geodesics
13
+ <https://www.Movable-Type.co.UK/scripts/LatLongVincenty.html>}. More
14
+ at U{geographiclib<https://PyPI.org/project/geographiclib>} and
15
+ U{GeoPy<https://PyPI.org/project/geopy>}.
16
+
17
+ Calculate geodesic distance between two points using the U{Vincenty
18
+ <https://WikiPedia.org/wiki/Vincenty's_formulae>} formulae and one of
19
+ several ellipsoidal earth models. The default model is WGS-84, the
20
+ most widely used globally-applicable model for the earth ellipsoid.
21
+
22
+ Other ellipsoids offering a better fit to the local geoid include Airy
23
+ (1830) in the UK, Clarke (1880) in Africa, International 1924 in much
24
+ of Europe, and GRS-67 in South America. North America (NAD83) and
25
+ Australia (GDA) use GRS-80, which is equivalent to the WGS-84 model.
26
+
27
+ Great-circle distance uses a I{spherical} model of the earth with the
28
+ mean earth radius defined by the International Union of Geodesy and
29
+ Geophysics (IUGG) as M{(2 * a + b) / 3 = 6371008.7714150598} or about
30
+ 6,371,009 meter (for WGS-84, resulting in an error of up to about 0.5%).
31
+
32
+ Here's an example usage of C{ellipsoidalVincenty}:
33
+
34
+ >>> from pygeodesy.ellipsoidalVincenty import LatLon
35
+ >>> Newport_RI = LatLon(41.49008, -71.312796)
36
+ >>> Cleveland_OH = LatLon(41.499498, -81.695391)
37
+ >>> Newport_RI.distanceTo(Cleveland_OH)
38
+ 866,455.4329158525 # meter
39
+
40
+ To change the ellipsoid model used by the Vincenty formulae use:
41
+
42
+ >>> from pygeodesy import Datums
43
+ >>> from pygeodesy.ellipsoidalVincenty import LatLon
44
+ >>> p = LatLon(0, 0, datum=Datums.OSGB36)
45
+
46
+ or by converting to anothor datum:
47
+
48
+ >>> p = p.toDatum(Datums.OSGB36)
49
+ '''
50
+ # make sure int/int division yields float quotient, see .basics
51
+ from __future__ import division as _; del _ # PYCHOK semicolon
52
+
53
+ from pygeodesy.constants import EPS, EPS0, _0_0, _1_0, _2_0, _3_0, _4_0, _6_0
54
+ from pygeodesy.ellipsoidalBase import CartesianEllipsoidalBase, _nearestOn
55
+ from pygeodesy.ellipsoidalBaseDI import LatLonEllipsoidalBaseDI, \
56
+ _intersection3, _intersections2, \
57
+ _TOL_M, intersecant2
58
+ from pygeodesy.errors import _and, _ValueError, _xkwds
59
+ from pygeodesy.fmath import Fpolynomial, hypot, hypot1
60
+ from pygeodesy.interns import _ambiguous_, _antipodal_, _COLONSPACE_, \
61
+ _to_, _SPACE_, _limit_ # PYCHOK used!
62
+ from pygeodesy.lazily import _ALL_DOCS, _ALL_LAZY, _ALL_MODS as _MODS, _ALL_OTHER
63
+ from pygeodesy.namedTuples import Destination2Tuple, Destination3Tuple, \
64
+ Distance3Tuple
65
+ from pygeodesy.points import Fmt, ispolar # PYCHOK exported
66
+ from pygeodesy.props import deprecated_function, deprecated_method, \
67
+ property_doc_, property_RO
68
+ # from pygeodesy.streprs import Fmt # from .points
69
+ from pygeodesy.units import Number_, Scalar_
70
+ from pygeodesy.utily import atan2b, atan2d, sincos2, sincos2d, unroll180, wrap180
71
+
72
+ from math import atan2, cos, degrees, fabs, radians, tan
73
+
74
+ __all__ = _ALL_LAZY.ellipsoidalVincenty
75
+ __version__ = '23.12.18'
76
+
77
+ _antipodal_to_ = _SPACE_(_antipodal_, _to_)
78
+
79
+
80
+ class VincentyError(_ValueError):
81
+ '''Error raised by I{Vincenty}'s C{Direct} and C{Inverse} methods
82
+ for coincident points or lack of convergence.
83
+ '''
84
+ pass
85
+
86
+
87
+ class Cartesian(CartesianEllipsoidalBase):
88
+ '''Extended to convert geocentric, L{Cartesian} points to
89
+ Vincenty-based, ellipsoidal, geodetic L{LatLon}.
90
+ '''
91
+ @property_RO
92
+ def Ecef(self):
93
+ '''Get the ECEF I{class} (L{EcefVeness}), I{once}.
94
+ '''
95
+ return _Ecef()
96
+
97
+ def toLatLon(self, **LatLon_and_kwds): # PYCHOK LatLon=LatLon, datum=None
98
+ '''Convert this cartesian point to a C{Vincenty}-based geodetic point.
99
+
100
+ @kwarg LatLon_and_kwds: Optional L{LatLon} and L{LatLon} keyword
101
+ arguments as C{datum}. Use C{B{LatLon}=...,
102
+ B{datum}=...} to override this L{LatLon}
103
+ class or specify C{B{LatLon}=None}.
104
+
105
+ @return: The geodetic point (L{LatLon}) or if B{C{LatLon}} is C{None},
106
+ an L{Ecef9Tuple}C{(x, y, z, lat, lon, height, C, M, datum)}
107
+ with C{C} and C{M} if available.
108
+
109
+ @raise TypeError: Invalid B{C{LatLon_and_kwds}} argument.
110
+ '''
111
+ kwds = _xkwds(LatLon_and_kwds, LatLon=LatLon, datum=self.datum)
112
+ return CartesianEllipsoidalBase.toLatLon(self, **kwds)
113
+
114
+
115
+ class LatLon(LatLonEllipsoidalBaseDI):
116
+ '''New point on an (oblate) ellipsoidal earth model, using the formulae devised
117
+ by U{I{Thaddeus Vincenty}<https://WikiPedia.org/wiki/Vincenty's_formulae>}
118
+ (1975) to compute geodesic distances, bearings (azimuths), etc.
119
+
120
+ Set the earth model to be used with the keyword argument datum. The default
121
+ is C{Datums.WGS84}, which is the most globally accurate. For other models,
122
+ see the L{Datums<pygeodesy.datums>}.
123
+
124
+ @note: This implementation of I{Vincenty} methods may not converge for some
125
+ valid points, raising a L{VincentyError}. In that case, a result may
126
+ be obtained by increasing the tolerance C{epsilon} and/or iteration
127
+ C{limit}, see properties L{LatLon.epsilon} and L{LatLon.iterations}.
128
+ '''
129
+ _epsilon = 1e-12 # radians, about 6 um
130
+ # _iteration = None # iteration number from .named._NamedBase
131
+ _iterations = 201 # 5, default max, 200 vs Veness' 1,000
132
+
133
+ @deprecated_method
134
+ def bearingTo(self, other, wrap=False): # PYCHOK no cover
135
+ '''DEPRECATED, use method L{initialBearingTo} or L{bearingTo2}.
136
+ '''
137
+ return self.initialBearingTo(other, wrap=wrap)
138
+
139
+ @property_RO
140
+ def Ecef(self):
141
+ '''Get the ECEF I{class} (L{EcefVeness}), I{once}.
142
+ '''
143
+ return _Ecef()
144
+
145
+ @property_doc_(''' the convergence epsilon (C{radians}).''')
146
+ def epsilon(self):
147
+ '''Get the convergence epsilon (C{radians}).
148
+ '''
149
+ return self._epsilon
150
+
151
+ @epsilon.setter # PYCHOK setter!
152
+ def epsilon(self, epsilon):
153
+ '''Set the convergence epsilon (C{radians}).
154
+
155
+ @raise TypeError: Non-scalar B{C{epsilon}}.
156
+
157
+ @raise ValueError: Out of bounds B{C{epsilon}}.
158
+ '''
159
+ self._epsilon = Scalar_(epsilon=epsilon)
160
+
161
+ @property_doc_(''' the iteration limit (C{int}).''')
162
+ def iterations(self):
163
+ '''Get the iteration limit (C{int}).
164
+ '''
165
+ return self._iterations - 1
166
+
167
+ @iterations.setter # PYCHOK setter!
168
+ def iterations(self, limit):
169
+ '''Set the iteration limit (C{int}).
170
+
171
+ @raise TypeError: Non-scalar B{C{limit}}.
172
+
173
+ @raise ValueError: Out-of-bounds B{C{limit}}.
174
+ '''
175
+ self._iterations = Number_(limit, name=_limit_, low=4, high=1000) + 1
176
+
177
+ def toCartesian(self, **Cartesian_datum_kwds): # PYCHOK Cartesian=Cartesian, datum=None
178
+ '''Convert this point to C{Vincenty}-based cartesian (ECEF)
179
+ coordinates.
180
+
181
+ @kwarg Cartesian_datum_kwds: Optional L{Cartesian}, B{C{datum}} and other
182
+ keyword arguments, ignored if C{B{Cartesian}=None}. Use
183
+ C{B{Cartesian}=...} to override this L{Cartesian} class
184
+ or specify C{B{Cartesian}=None}.
185
+
186
+ @return: The cartesian point (L{Cartesian}) or if B{C{Cartesian}}
187
+ is C{None}, an L{Ecef9Tuple}C{(x, y, z, lat, lon, height,
188
+ C, M, datum)} with C{C} and C{M} if available.
189
+
190
+ @raise TypeError: Invalid B{C{Cartesian}}, B{C{datum}} or other
191
+ B{C{Cartesian_datum_kwds}}.
192
+ '''
193
+ kwds = _xkwds(Cartesian_datum_kwds, Cartesian=Cartesian,
194
+ datum=self.datum)
195
+ return LatLonEllipsoidalBaseDI.toCartesian(self, **kwds)
196
+
197
+ def _Direct(self, distance, bearing, llr, height):
198
+ '''(INTERNAL) Direct Vincenty method.
199
+
200
+ @raise TypeError: The B{C{other}} point is not L{LatLon}.
201
+
202
+ @raise ValueError: If this and the B{C{other}} point's L{Datum}
203
+ ellipsoids are not compatible.
204
+
205
+ @raise VincentyError: Vincenty fails to converge for the current
206
+ L{LatLon.epsilon} and L{LatLon.iterations}
207
+ limits.
208
+ '''
209
+ E = self.ellipsoid()
210
+ f = E.f
211
+
212
+ sb, cb = sincos2d(bearing)
213
+ s1, c1, t1 = _sincostan3r(self.phi, f)
214
+
215
+ eps = self.epsilon
216
+ s12 = atan2(t1, cb) * _2_0
217
+ sa, ca2 = _sincos22(c1 * sb)
218
+ A, B = _AB2(ca2 * E.e22) # e22 == (a / b)**2 - 1
219
+ s = d = distance / (A * E.b)
220
+ for i in range(1, self._iterations): # 1-origin
221
+ ss, cs = sincos2(s)
222
+ c2sm, e = cos(s12 + s), s
223
+ s = _Ds(B, cs, ss, c2sm, d)
224
+ e = fabs(s - e)
225
+ if e < eps:
226
+ self._iteration = i
227
+ break
228
+ else:
229
+ t = self._no_convergence(e)
230
+ raise VincentyError(t, txt=repr(self)) # self.toRepr()
231
+
232
+ t = s1 * ss - c1 * cs * cb
233
+ # final bearing (reverse azimuth +/- 180)
234
+ d = atan2b(sa, -t)
235
+ if llr:
236
+ b = cb * ss
237
+ a = atan2d(s1 * cs + c1 * b, hypot(sa, t) * E.b_a)
238
+ b = atan2d(sb * ss, -s1 * b + c1 * cs) + self.lon \
239
+ - degrees(_Dl(f, ca2, sa, s, cs, ss, c2sm))
240
+ t = Destination3Tuple(a, wrap180(b), d)
241
+ r = self._Direct2Tuple(self.classof, height, t)
242
+ else:
243
+ r = Destination2Tuple(None, d, name=self.name)
244
+ r._iteration = i
245
+ return r
246
+
247
+ def _Inverse(self, other, wrap, azis=True): # PYCHOK signature
248
+ '''(INTERNAL) Inverse Vincenty method.
249
+
250
+ @raise TypeError: The B{C{other}} point is not L{LatLon}.
251
+
252
+ @raise ValueError: If this and the B{C{other}} point's L{Datum}
253
+ ellipsoids are not compatible.
254
+
255
+ @raise VincentyError: Vincenty fails to converge for the current
256
+ L{LatLon.epsilon} and L{LatLon.iterations}
257
+ limits and/or if this and the B{C{other}}
258
+ point are coincident or near-antipodal.
259
+ '''
260
+ E = self.ellipsoids(other)
261
+ f = E.f
262
+
263
+ s1, c1, _ = _sincostan3r( self.phi, f)
264
+ s2, c2, _ = _sincostan3r(other.phi, f)
265
+
266
+ c1c2, s1c2 = c1 * c2, s1 * c2
267
+ c1s2, s1s2 = c1 * s2, s1 * s2
268
+
269
+ eps = self.epsilon
270
+ d, _ = unroll180(self.lon, other.lon, wrap=wrap)
271
+ dl = ll = radians(d)
272
+ for i in range(1, self._iterations): # 1-origin
273
+ sll, cll = sincos2(ll)
274
+
275
+ ss = hypot(c2 * sll, c1s2 - s1c2 * cll)
276
+ if ss < EPS: # coincident or antipodal, ...
277
+ if self.isantipodeTo(other, eps=eps):
278
+ t = self._is_to(other, True)
279
+ raise VincentyError(_ambiguous_, txt=t)
280
+ self._iteration = i
281
+ # return zeros like Karney, unlike Veness
282
+ return Distance3Tuple(_0_0, 0, 0, iteration=i)
283
+
284
+ cs = s1s2 + c1c2 * cll
285
+ s, e = atan2(ss, cs), ll
286
+ sa, ca2 = _sincos22(c1c2 * sll / ss)
287
+ if ca2:
288
+ c2sm = cs - _2_0 * s1s2 / ca2
289
+ ll = _Dl(f, ca2, sa, s, cs, ss, c2sm, dl)
290
+ else: # equatorial line
291
+ ll = dl + f * sa * s
292
+ e = fabs(ll - e)
293
+ if e < eps:
294
+ self._iteration = i
295
+ break
296
+ # elif abs(ll) > PI and self.isantipodeTo(other, eps=eps):
297
+ # # omitted and applied *after* failure to converge below,
298
+ # # see footnote under Inverse <https://WikiPedia.org/wiki/
299
+ # # Vincenty's_formulae> and <https://GitHub.com/chrisveness/
300
+ # # geodesy/blob/master/latlon-ellipsoidal-vincenty.js>
301
+ # raise VincentyError(_ambiguous_, self._is_to(other, True))
302
+ else:
303
+ t = self._is_to(other, self.isantipodeTo(other, eps=eps))
304
+ raise VincentyError(self._no_convergence(e), txt=t)
305
+
306
+ if ca2: # e22 == (a / b)**2 - 1
307
+ A, B = _AB2(ca2 * E.e22)
308
+ s = -A * _Ds(B, cs, ss, c2sm, -s)
309
+
310
+ b = E.b
311
+ # if self.height or other.height:
312
+ # b += self._havg(other)
313
+ d = b * s
314
+
315
+ if azis: # forward and reverse azimuth
316
+ s, c = sincos2(ll)
317
+ f = atan2b(c2 * s, c1s2 - s1c2 * c)
318
+ r = atan2b(c1 * s, -s1c2 + c1s2 * c)
319
+ else:
320
+ f = r = _0_0 # NAN
321
+ return Distance3Tuple(d, f, r, name=self.name, iteration=i)
322
+
323
+ def _is_to(self, other, anti):
324
+ '''(INTERNAL) Return I{'<self> [antipodal] to <other>'} text (C{str}).
325
+ '''
326
+ t = _antipodal_to_ if anti else _to_
327
+ return _SPACE_(repr(self), t, repr(other))
328
+
329
+ def _no_convergence(self, e):
330
+ '''(INTERNAL) Return I{'no convergence (..): ...'} text (C{str}).
331
+ '''
332
+ t = (Fmt.PARENSPACED(*t) for t in ((LatLon.epsilon.name, self.epsilon),
333
+ (LatLon.iterations.name, self.iterations)))
334
+ return _COLONSPACE_(Fmt.no_convergence(e), _and(*t))
335
+
336
+
337
+ def _AB2(u2): # WGS84 e22 = 0.00673949674227643
338
+ # 2-Tuple C{(A, B)} polynomials
339
+ if u2:
340
+ A = Fpolynomial(u2, 16384, 4096, -768, 320, -175).fover(16384)
341
+ B = Fpolynomial(u2, 0, 256, -128, 74, -47).fover( 1024)
342
+ return A, B
343
+ return _1_0, _0_0
344
+
345
+
346
+ def _c2sm2(c2sm):
347
+ # C{2 * c2sm**2 - 1}
348
+ return c2sm**2 * _2_0 - _1_0
349
+
350
+
351
+ def _Dl(f, ca2, sa, s, cs, ss, c2sm, dl=_0_0):
352
+ # C{Dl}
353
+ if f and sa:
354
+ C = f * ca2 / _4_0
355
+ C *= f - C * _3_0 + _1_0
356
+ if C and ss:
357
+ s += C * ss * (c2sm +
358
+ C * cs * _c2sm2(c2sm))
359
+ dl += (_1_0 - C) * f * sa * s
360
+ return dl
361
+
362
+
363
+ def _Ds(B, cs, ss, c2sm, d):
364
+ # C{Ds - d}
365
+ if B and ss:
366
+ c2sm2 = _c2sm2(c2sm)
367
+ ss2 = (ss**2 * _4_0 - _3_0) * (c2sm2 * _2_0 - _1_0)
368
+ B *= ss * (c2sm + B / _4_0 * (c2sm2 * cs -
369
+ B / _6_0 * c2sm * ss2))
370
+ d += B
371
+ return d
372
+
373
+
374
+ def _Ecef():
375
+ # get the Ecef class and overwrite property_RO
376
+ Cartesian.Ecef = LatLon.Ecef = E = _MODS.ecef.EcefVeness
377
+ return E
378
+
379
+
380
+ def _sincos22(sa):
381
+ # 2-Tuple C{(sin(a), cos(a)**2)}
382
+ ca2 = _1_0 - sa**2
383
+ return sa, (_0_0 if ca2 < EPS0 else ca2) # XXX EPS?
384
+
385
+
386
+ def _sincostan3r(a, f):
387
+ # I{Reduced} 3-tuple C{(sin(B{a}), cos(B{a}), tan(B{a}))}
388
+ if a: # see L{sincostan3}
389
+ t = (_1_0 - f) * tan(a)
390
+ if t:
391
+ c = _1_0 / hypot1(t)
392
+ s = c * t
393
+ return s, c, t
394
+ return _0_0, _1_0, _0_0
395
+
396
+
397
+ @deprecated_function
398
+ def areaOf(points, **datum_wrap):
399
+ '''DEPRECATED, use function L{ellipsoidalExact.areaOf} or L{ellipsoidalKarney.areaOf}.
400
+ '''
401
+ try:
402
+ return _MODS.ellipsoidalKarney.areaOf(points, **datum_wrap)
403
+ except ImportError:
404
+ return _MODS.ellipsoidalExact.areaOf(points, **datum_wrap)
405
+
406
+
407
+ def intersection3(start1, end1, start2, end2, height=None, wrap=False, # was=True
408
+ equidistant=None, tol=_TOL_M, LatLon=LatLon, **LatLon_kwds):
409
+ '''I{Iteratively} compute the intersection point of two lines, each defined
410
+ by two (ellipsoidal) points or by an (ellipsoidal) start point and an
411
+ (initial) bearing from North.
412
+
413
+ @arg start1: Start point of the first line (L{LatLon}).
414
+ @arg end1: End point of the first line (L{LatLon}) or the initial bearing
415
+ at the first point (compass C{degrees360}).
416
+ @arg start2: Start point of the second line (L{LatLon}).
417
+ @arg end2: End point of the second line (L{LatLon}) or the initial bearing
418
+ at the second point (compass C{degrees360}).
419
+ @kwarg height: Optional height at the intersection (C{meter}, conventionally)
420
+ or C{None} for the mean height.
421
+ @kwarg wrap: If C{True}, wrap or I{normalize} and unroll the B{C{start2}}
422
+ and B{C{end*}} points (C{bool}).
423
+ @kwarg equidistant: An azimuthal equidistant projection (I{class} or function
424
+ L{pygeodesy.equidistant}) or C{None} for the preferred
425
+ C{B{start1}.Equidistant}.
426
+ @kwarg tol: Tolerance for convergence and for skew line distance and length
427
+ (C{meter}, conventionally).
428
+ @kwarg LatLon: Optional class to return the intersection points (L{LatLon})
429
+ or C{None}.
430
+ @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword arguments,
431
+ ignored if C{B{LatLon} is None}.
432
+
433
+ @return: An L{Intersection3Tuple}C{(point, outside1, outside2)} with C{point}
434
+ a B{C{LatLon}} or if C{B{LatLon} is None}, a L{LatLon4Tuple}C{(lat,
435
+ lon, height, datum)}.
436
+
437
+ @raise IntersectionError: Skew, colinear, parallel or otherwise
438
+ non-intersecting lines or no convergence
439
+ for the given B{C{tol}}.
440
+
441
+ @raise TypeError: Invalid or non-ellipsoidal B{C{start1}}, B{C{end1}},
442
+ B{C{start2}} or B{C{end2}} or invalid B{C{equidistant}}.
443
+
444
+ @note: For each line specified with an initial bearing, a pseudo-end point
445
+ is computed as the C{destination} along that bearing at about 1.5
446
+ times the distance from the start point to an initial gu-/estimate
447
+ of the intersection point (and between 1/8 and 3/8 of the authalic
448
+ earth perimeter).
449
+
450
+ @see: U{The B{ellipsoidal} case<https://GIS.StackExchange.com/questions/48937/
451
+ calculating-intersection-of-two-circles>} and U{Karney's paper
452
+ <https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section B{14. MARITIME
453
+ BOUNDARIES} for more details about the iteration algorithm.
454
+ '''
455
+ return _intersection3(start1, end1, start2, end2, height=height, wrap=wrap,
456
+ equidistant=equidistant, tol=tol, LatLon=LatLon, **LatLon_kwds)
457
+
458
+
459
+ def intersections2(center1, radius1, center2, radius2, height=None, wrap=False, # was=True
460
+ equidistant=None, tol=_TOL_M, LatLon=LatLon, **LatLon_kwds):
461
+ '''I{Iteratively} compute the intersection points of two circles, each defined
462
+ by an (ellipsoidal) center point and a radius.
463
+
464
+ @arg center1: Center of the first circle (L{LatLon}).
465
+ @arg radius1: Radius of the first circle (C{meter}, conventionally).
466
+ @arg center2: Center of the second circle (L{LatLon}).
467
+ @arg radius2: Radius of the second circle (C{meter}, same units as
468
+ B{C{radius1}}).
469
+ @kwarg height: Optional height for the intersection points (C{meter},
470
+ conventionally) or C{None} for the I{"radical height"}
471
+ at the I{radical line} between both centers.
472
+ @kwarg wrap: If C{True}, wrap or I{normalize} and unroll B{C{center2}}
473
+ (C{bool}).
474
+ @kwarg equidistant: An azimuthal equidistant projection (I{class} or
475
+ function L{pygeodesy.equidistant}) or C{None} for
476
+ the preferred C{B{center1}.Equidistant}.
477
+ @kwarg tol: Convergence tolerance (C{meter}, same units as B{C{radius1}}
478
+ and B{C{radius2}}).
479
+ @kwarg LatLon: Optional class to return the intersection points (L{LatLon})
480
+ or C{None}.
481
+ @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword arguments,
482
+ ignored if C{B{LatLon} is None}.
483
+
484
+ @return: 2-Tuple of the intersection points, each a B{C{LatLon}} instance
485
+ or L{LatLon4Tuple}C{(lat, lon, height, datum)} if C{B{LatLon} is
486
+ None}. For abutting circles, both points are the same instance,
487
+ aka the I{radical center}.
488
+
489
+ @raise IntersectionError: Concentric, antipodal, invalid or non-intersecting
490
+ circles or no convergence for the B{C{tol}}.
491
+
492
+ @raise TypeError: Invalid or non-ellipsoidal B{C{center1}} or B{C{center2}}
493
+ or invalid B{C{equidistant}}.
494
+
495
+ @raise UnitError: Invalid B{C{radius1}}, B{C{radius2}} or B{C{height}}.
496
+
497
+ @see: U{The B{ellipsoidal} case<https://GIS.StackExchange.com/questions/48937/
498
+ calculating-intersection-of-two-circles>}, U{Karney's paper
499
+ <https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section B{14. MARITIME BOUNDARIES},
500
+ U{circle-circle<https://MathWorld.Wolfram.com/Circle-CircleIntersection.html>} and
501
+ U{sphere-sphere<https://MathWorld.Wolfram.com/Sphere-SphereIntersection.html>}
502
+ intersections.
503
+ '''
504
+ return _intersections2(center1, radius1, center2, radius2, height=height, wrap=wrap,
505
+ equidistant=equidistant, tol=tol, LatLon=LatLon, **LatLon_kwds)
506
+
507
+
508
+ def nearestOn(point, point1, point2, within=True, height=None, wrap=False,
509
+ equidistant=None, tol=_TOL_M, LatLon=LatLon, **LatLon_kwds):
510
+ '''I{Iteratively} locate the closest point on the geodesic between
511
+ two other (ellipsoidal) points.
512
+
513
+ @arg point: Reference point (C{LatLon}).
514
+ @arg point1: Start point of the geodesic (C{LatLon}).
515
+ @arg point2: End point of the geodesic (C{LatLon}).
516
+ @kwarg within: If C{True} return the closest point I{between}
517
+ B{C{point1}} and B{C{point2}}, otherwise the
518
+ closest point elsewhere on the geodesic (C{bool}).
519
+ @kwarg height: Optional height for the closest point (C{meter},
520
+ conventionally) or C{None} or C{False} for the
521
+ interpolated height. If C{False}, the closest
522
+ takes the heights of the points into account.
523
+ @kwarg wrap: If C{True}, wrap or I{normalize} and unroll both
524
+ B{C{point1}} and B{C{point2}} (C{bool}).
525
+ @kwarg equidistant: An azimuthal equidistant projection (I{class}
526
+ or function L{pygeodesy.equidistant}) or C{None}
527
+ for the preferred C{B{point}.Equidistant}.
528
+ @kwarg tol: Convergence tolerance (C{meter}).
529
+ @kwarg LatLon: Optional class to return the closest point
530
+ (L{LatLon}) or C{None}.
531
+ @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword
532
+ arguments, ignored if C{B{LatLon} is None}.
533
+
534
+ @return: Closest point, a B{C{LatLon}} instance or if C{B{LatLon}
535
+ is None}, a L{LatLon4Tuple}C{(lat, lon, height, datum)}.
536
+
537
+ @raise ImportError: Package U{geographiclib
538
+ <https://PyPI.org/project/geographiclib>}
539
+ not installed or not found, but only if
540
+ C{B{equidistant}=}L{EquidistantKarney}.
541
+
542
+ @raise TypeError: Invalid or non-ellipsoidal B{C{point}}, B{C{point1}}
543
+ or B{C{point2}} or invalid B{C{equidistant}}.
544
+
545
+ @raise ValueError: No convergence for the B{C{tol}}.
546
+
547
+ @see: U{The B{ellipsoidal} case<https://GIS.StackExchange.com/questions/48937/
548
+ calculating-intersection-of-two-circles>} and U{Karney's paper
549
+ <https://ArXiv.org/pdf/1102.1215.pdf>}, pp 20-21, section B{14. MARITIME
550
+ BOUNDARIES} for more details about the iteration algorithm.
551
+ '''
552
+ return _nearestOn(point, point1, point2, within=within, height=height, wrap=wrap,
553
+ equidistant=equidistant, tol=tol, LatLon=LatLon, **LatLon_kwds)
554
+
555
+
556
+ @deprecated_function
557
+ def perimeterOf(points, **closed_datum_wrap):
558
+ '''DEPRECATED, use function L{ellipsoidalExact.perimeterOf} or L{ellipsoidalKarney.perimeterOf}.
559
+ '''
560
+ try:
561
+ return _MODS.ellipsoidalKarney.perimeterOf(points, **closed_datum_wrap)
562
+ except ImportError:
563
+ return _MODS.ellipsoidalExact.perimeterOf(points, **closed_datum_wrap)
564
+
565
+
566
+ __all__ += _ALL_OTHER(Cartesian, LatLon, intersecant2, # from .ellipsoidalBaseDI
567
+ intersection3, intersections2, ispolar, # from .points
568
+ nearestOn) + _ALL_DOCS(areaOf, perimeterOf) # deprecated
569
+
570
+ # **) MIT License
571
+ #
572
+ # Copyright (C) 2016-2024 -- mrJean1 at Gmail -- All Rights Reserved.
573
+ #
574
+ # Permission is hereby granted, free of charge, to any person obtaining a
575
+ # copy of this software and associated documentation files (the "Software"),
576
+ # to deal in the Software without restriction, including without limitation
577
+ # the rights to use, copy, modify, merge, publish, distribute, sublicense,
578
+ # and/or sell copies of the Software, and to permit persons to whom the
579
+ # Software is furnished to do so, subject to the following conditions:
580
+ #
581
+ # The above copyright notice and this permission notice shall be included
582
+ # in all copies or substantial portions of the Software.
583
+ #
584
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
585
+ # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
586
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
587
+ # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
588
+ # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
589
+ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
590
+ # OTHER DEALINGS IN THE SOFTWARE.