Coverage for pybelbg / __pygeodesy.py: 99%

67 statements  

« prev     ^ index     » next       coverage.py v7.14.0, created at 2026-08-21 15:07 -0400

1 

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

3 

4u'''(INTERNAL) C{pybelbg} access to some private C{pygeodesy} attributes. 

5''' 

6import os.path as os_path 

7import sys # PYCHOK used! 

8 

9_missing_ = 'missing' # PYCHOK used! 

10_requires = '26.8.18' # in README.rst, requirements.txt, setup.py 

11 

12 

13def _PyGeodesy_dir(requires): 

14 # Adjust sys.path to enable import pygeodesy 

15 d = None 

16 try: 

17 from pygeodesy import version as _v 

18 except ImportError: 

19 _v = _missing_ 

20 # PYTHONPATH=.../PyBeLBG for development ONLY 

21 p = os_path.abspath(__file__) 

22 p = os_path.dirname(p) # pybelbg_abspath 

23 p = os_path.dirname(p) # PyBeLBG 

24 p = os_path.dirname(p) # ../ 

25 g = os_path.join(p, 'PyGeodesy') 

26 if g != p and g not in sys.path: 

27 sys.path.insert(0, g) 

28 try: 

29 from pygeodesy import version as _v # PYCHOK redef 

30 d = g 

31 except ImportError: 

32 pass 

33# finally: 

34# try: 

35# sys.path.remove(g) 

36# except ValueError: 

37# pass 

38 

39 def _t(v): 

40 return tuple(map(int, v.split('.'))) # _DOT_ 

41 

42 if _v == _missing_ or _t(_v) < _t(requires): 

43 _v = ' %s, need %s or newer' % (_v, requires) 

44 raise ImportError('pygeodesy' + _v) 

45 

46 return d # or None 

47 

48_PyGeodesy_dir = _PyGeodesy_dir(_requires) # PYCHOK path or None 

49 

50from pygeodesy.basics import _xinstanceof, _xsubclassof # noqa: F401 

51from pygeodesy.constants import (_1_0, _3600_0, # noqa: F401 

52 _isNAN, _isNAN0) # noqa: F401 

53from pygeodesy.ellipsoidalBase import LatLonEllipsoidalBase as _LLEB # noqa: F401 

54from pygeodesy.errors import _ValueError, _xkwds # noqa: F401 

55from pygeodesy.internals import machine, _secs2str, _versions # noqa: F401 

56from pygeodesy.interns import (_COMMA_, _DASH_, _DOT_, _easting_, # noqa: F401 

57 _H_, _height_, _lat_, _lon_, _N_, # noqa: F401 

58 _name_, _northing_, _SPACE_) # noqa: F401 

59from pygeodesy.lazily import _ALL_DOCS, _ALL_OTHER, _ALL_STAR, _FOR_DOCS # noqa: F401 

60from pygeodesy.named import _NamedBase, _NamedTuple, _Pass # noqa: F401 

61from pygeodesy.namedTuples import (EasNor2Tuple, EasNor3Tuple, _isinside, # noqa: F401 

62 _H_lat_lon_height4Tuple, _resize4) # noqa: F401 

63from pygeodesy.streprs import Fmt # noqa: F401 

64 

65from pygeodesy import (Datums, Easting, Meter, Northing, Property_RO) 

66 

67 

68class BeLBGError(_ValueError): 

69 '''Error raised for C{pybelbg}, C{hBG18}, unzip and other issues. 

70 ''' 

71 pass 

72 

73 

74class BeLBG7Tuple(_H_lat_lon_height4Tuple): 

75 '''7-Tuple C{(easting, northing, H, lat, lon, height, beLBG)} with I{local} 

76 Belgian C{easting}, C{northing} and orthometric height C{H}, geodetic C{lat}, 

77 C{lon} and ellipsoidal C{height} and C{beLBG} the C{Be*LBG} instance with 

78 C{lat} and C{lon} in C{degrees} and with C{easting}, C{northing}, C{H} and 

79 C{height} in C{meter}, conventionally. 

80 ''' 

81 _Names_ = (_easting_, _northing_) + _H_lat_lon_height4Tuple._Names_ + ('beLBG',) 

82 _Units_ = ( Easting, Northing) + _H_lat_lon_height4Tuple._Units_ + (_Pass,) 

83 

84 @Property_RO 

85 def datum(self): 

86 '''Get the C{beLBG}'s datum (C{Datum}). 

87 ''' 

88 return self.beLBG.datum # PYCHOK beLBG 

89 

90# def diff(self, other, datum=None, **name): 

91# '''Return the difference between this and an C{other} C{BeLBG7Tuple}. 

92# 

93# @kwarg datum: Datum C{diff} (C{Datum}, None or NAN). 

94# @kwarg name: Optional name (C{str}). 

95# 

96# @return: An L{BeLBG7Tuple} with the C{fabs(diff)} for each item, 

97# except C{datum} as B{C{datum}}. 

98# ''' 

99# def _diff(a, b): 

100# try: 

101# return fabs(a - b) 

102# except TypeError: 

103# return datum 

104# 

105# _xinstanceof(BeLBG7Tuple, other=other) 

106# t = map2(_diff, self, other) 

107# return BeLBG7Tuple(t, **name) 

108 

109 @Property_RO 

110 def eastingnorthing(self): 

111 '''Get 2-tuple (L{EasNor2Tuple}C{(easting, northing)}). 

112 ''' 

113 return EasNor2Tuple(self.easting, self.northing, name=self.name) 

114 

115 @Property_RO 

116 def eastingnorthingheight(self): 

117 '''Get 3-tuple L{EasNor3Tuple}C{(easting, northing, height)} with ellipsoidal C{height}. 

118 ''' 

119 return EasNor3Tuple(self.easting, self.northing, self.height, name=self.name) 

120 

121 @Property_RO 

122 def eastingnorthingHeight(self): 

123 '''Get 3-tuple L{EasNorHeight3Tuple}C{(easting, northing, H)} with orthometric height C{H}. 

124 ''' 

125 return EasNorHeight3Tuple(self.easting, self.northing, self.H, name=self.name) 

126 

127 @Property_RO 

128 def eastingnorthingNgeoid(self): 

129 '''Get 3-tuple L{EasNorNgeoid3Tuple}C{(easting, northing, N)} with geoid height C{N}. 

130 ''' 

131 return EasNorNgeoid3Tuple(self.easting, self.northing, self.N, name=self.name) 

132 

133# def isinside2(self, asLb=False): 

134# '''Return 2-tuple C{(region4, bounds4)}, each C{True} if this point is 

135# inside this C{region4} respectively C{bounds4} otherwise C{False}. 

136# ''' 

137# t = (self.easting, self.northing) if asLB else (self.lat, self.lon) 

138# return (self.beLBG.region4(asLb)(*t), 

139# self.beLBG.bounds4(asLb)(*t)) 

140 

141 @Property_RO 

142 def latlonheightdatum(self): 

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

144 ''' 

145 return self.latlonheight.to4Tuple(self.datum) 

146 

147 @Property_RO 

148 def philamheightdatum(self): 

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

150 ''' 

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

152 

153# def toDatum(self, datum2, name=NN): 

154# '''Convert this C{lat}, C{lon} and C{height} to B{C{datum2}}. 

155# 

156# @arg datum2: Datum to convert I{to} (L{Datum}). 

157# @kwarg name: Optional name (C{str}), overriding this name. 

158# 

159# @return: An L{BeLBG7Tuple} with transformed C{lat}, C{lon} and C{height} 

160# or this L{BeLBG7Tuple} if this.datum is B{C{datum2}}. 

161# ''' 

162# _xinstanceof(Datum, datum2=datum2) 

163# if self.datum is datum2 or self.datum == datum2: # PYCHOK datum 

164# return self 

165# g = self.toLatLon(_LLEB).toDatum(datum2) 

166# h = NAN if _isNAN(self.height) else g.height # PYCHOK preserve height NAN 

167# return self.dup(lat=g.lat, lon=g.lon, datum=g.datum, height=h, 

168# name=name or self.name) 

169 

170# def toLatLon(self, LatLon, **LatLon_kwds): 

171# '''Return this C{lat}, C{lon}, C{datum} and C{height} as B{C{LatLon}}. 

172# 

173# @arg LatLon: An ellipsoidal C{LatLon} class (C{pygeodesy.ellipsoidal*}). 

174# @kwarg LatLon_kwds: Optional, additional B{C{LatLon}} keyword arguments. 

175# 

176# @return: An B{C{LatLon}} instance. 

177# 

178# @raise TypeError: B{C{LatLon}} not ellipsoidal or an other issue. 

179# ''' 

180# _xsubclassof(_LLEB, LatLon=LatLon) 

181# h = _isNAN0(self.height) # PYCHOK height 

182# kwds = _xkwds(LatLon_kwds, name=self.name, height=h) 

183# return LatLon(self.lat, self.lon, datum=self.datum, **kwds) # PYCHOK datum 

184 

185 

186class EasNorHeight3Tuple(_NamedTuple): 

187 '''3-Tuple C{(easting, northing, H)} with orthometric height C{H}, all in C{meter}, conventionally. 

188 ''' 

189 _Names_ = BeLBG7Tuple._Names_[:3] 

190 _Units_ = BeLBG7Tuple._Units_[:3] 

191 

192 

193class EasNorNgeoid3Tuple(_NamedTuple): 

194 '''3-Tuple C{(easting, northing, N)} with geoid height C{N}, all in C{meter}, conventionally. 

195 ''' 

196 _Names_ = EasNorHeight3Tuple._Names_[:2] + (_N_,) 

197 _Units_ = EasNorHeight3Tuple._Units_ 

198 

199 

200class Lb4Tuple(_NamedTuple): 

201 '''4-Tuple C{(minE, minN, maxE, maxN)} with local C{Lambert} lower-left 

202 C{(minE, minN)} and upper-right C{(maxE, maxN)} easting and northing 

203 bounds in C{meter}, conventionally. 

204 ''' 

205 _Names_ = ('minE', 'minN', 'maxE', 'maxN') 

206 _Units_ = ( Easting, Northing, Easting, Northing) 

207 

208 def isinside(self, easting, northing, eps=0): 

209 '''Are B{C{easting}} and B{C{northing}} inside these C{Lambert} bounds? 

210 

211 @arg easting: Easting (C{meter}). 

212 @arg northing: Northing (C{meter}). 

213 @kwarg eps: Over-/undersize the C{Lb} bounds (C{meter}). 

214 

215 @return: C{False} if B{C{easting}} or B{C{northing}} is C{NAN} 

216 or outsize these C{Lb} bounds, C{True} otherwise. 

217 ''' 

218 z = Meter(eps=eps) if eps else 0 

219 return _isinside(Easting(easting), Northing(northing), z, self) 

220 

221 def resize(self, eps): 

222 '''Get these C{Lambert} bounds, over- or undersized by C{B{eps}}. 

223 

224 @arg eps: In- or decrease (C{meter}). 

225 

226 @return: An L{Lb4Tuple}C{(minE, minN, maxE, maxN)} with all 

227 4 bounds resized. 

228 ''' 

229 return _resize4(self, Meter(eps=eps)) 

230 

231 

232__all__ = _ALL_OTHER(BeLBGError, BeLBG7Tuple, Datums, EasNor3Tuple, 

233 EasNorHeight3Tuple, EasNorNgeoid3Tuple, Lb4Tuple, machine) 

234__version__ = '26.08.18' 

235 

236# **) MIT License 

237# 

238# Copyright (C) 2026-2026 -- mrJean1 at Gmail -- All Rights Reserved. 

239# 

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

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

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

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

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

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

246# 

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

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

249# 

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

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

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

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

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

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

256# OTHER DEALINGS IN THE SOFTWARE.