Coverage for pygeodesy/ltp.py : 94%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*-
I{Local cartesian} and I{local tangent plane} classes L{LocalCartesian} and L{Ltp}, L{LocalError} and L{Frustum}.
@see: U{Local tangent plane coordinates<https://WikiPedia.org/wiki/Local_tangent_plane_coordinates>} and class L{LocalCartesian}, transcoded from I{Charles Karney}'s C++ classU{LocalCartesian <https://GeographicLib.SourceForge.io/html/classGeographicLib_1_1LocalCartesian.html>}. '''
# from pygeodesy.basics import issubclassof # from ecef _llhn4, _xyzn4 _lon0_, _name_, _0_, _0_0, _0_5, \ _2_0, _90_0, _180_0, _360_0 _XyzLocals4, _XyzLocals5, Xyz4Tuple
'''A L{LocalCartesian} or L{Ltp} related issue. '''
'''Conversion between geodetic C{(lat, lon, height)} and I{local cartesian} C{(x, y, z)} coordinates with I{geodetic} origin C{(lat0, lon0, height0)}, transcoded from I{Karney}'s C++ class U{LocalCartesian <https://GeographicLib.SourceForge.io/html/classGeographicLib_1_1LocalCartesian.html>}.
The C{z} axis is normal to the ellipsoid, the C{y} axis points due North. The plane C{z = -height0} is tangent to the ellipsoid.
The conversions all take place via geocentric coordinates using a geocentric L{EcefKarney}, by default the WGS84 datum/ellipsoid.
@see: Class L{Ltp}. '''
'''New L{LocalCartesian} converter.
@kwarg latlonh0: Either a C{LatLon}, L{Ltp}, L{Ecef9Tuple} or C{scalar} latitude of the (goedetic) origin (C{degrees}). @kwarg lon0: Optional C{scalar} longitude of the (goedetic) origin C{scalar} B{C{latlonh0}} (C{degrees}). @kwarg height0: Optional origin height (C{meter}), vertically above (or below) the surface of the ellipsoid. @kwarg ecef: An ECEF converter (L{EcefKarney}). @kwarg name: Optional name (C{str}).
@raise LocalError: If B{C{latlonh0}} not C{LatLon}, L{Ecef9Tuple}, C{scalar} or invalid or if B{C{lon0}} not C{scalar} for C{scalar} B{C{latlonh0}} or invalid or if B{C{height0}} invalid.
@raise TypeError: Invalid B{C{ecef}}, not L{EcefKarney}.
@note: If BC{latlonh0} is L{Ltp}, only the lat-, longitude and height are duplicated, I{not} the ECEF converter. ''' _xinstanceof(EcefKarney, ecef=ecef) self._ecef = ecef
'''Get the ECEF converter's datum (L{Datum}). '''
'''Get the ECEF converter (L{EcefKarney}). '''
'''(INTERNAL) Convert geocentric/geodetic to local, like I{forward}.
@arg ecef: Geocentric (and geodetic) (L{Ecef9Tuple}). @arg Xyz: An L{XyzLocal}, L{Enu} or L{Ned} I{class} or C{None}. @arg Xyz_kwds: B{C{Xyz}} keyword arguments, ignored if C{B{Xyz}=None}.
@return: An C{B{Xyz}(x, y, z, ltp, **B{Xyz_kwds}} instance or if C{B{Xyz}=None}, an L{Local9Tuple}C{(x, y, z, lat, lon, height, ltp, ecef, M)} with this C{ltp}, B{C{ecef}} (L{Ecef9Tuple}) converted to this C{datum} and C{M=None}, always. ''' ecef = ecef.toDatum(ltp.datum) ltp, ecef, None, name=ecef.name) raise _TypesError(_Xyz_, Xyz, *_XyzLocals4)
'''Convert I{geodetic} C{(lat, lon, height)} to I{local} cartesian C{(x, y, z)}.
@arg latlonh: Either a C{LatLon}, a L{Ltp}, an L{Ecef9Tuple} or C{scalar} (geodetic) latitude (C{degrees}). @kwarg lon: Optional C{scalar} (geodetic) longitude for C{scalar} B{C{latlonh}} (C{degrees}). @kwarg height: Optional height (C{meter}), vertically above (or below) the surface of the ellipsoid. @kwarg M: Optionally, return the rotation L{EcefMatrix} (C{bool}). @kwarg name: Optional name (C{str}).
@return: A L{Local9Tuple}C{(x, y, z, lat, lon, height, ltp, ecef, M)} with I{local} C{x}, C{y}, C{z}, I{geodetic} C{(lat}, C{lon}, C{height}, this C{ltp}, C{ecef} (L{Ecef9Tuple}) with I{geocentric} C{x}, C{y}, C{z} (and I{geodetic} C{lat}, C{lon}, C{height}) and the I{concatenated} rotation matrix C{M} (L{EcefMatrix}) if requested.
@raise LocalError: If B{C{latlonh}} not C{scalar}, C{LatLon}, L{Ltp}, L{Ecef9Tuple} or invalid or if B{C{lon}} not C{scalar} for C{scalar} B{C{latlonh}} or invalid or if B{C{height}} invalid.
@see: Note at method L{EcefKarney.forward}. '''
'''Get origin's height (C{meter}). '''
'''Get origin's latitude (C{degrees}). '''
'''(INTERNAL) Convert I{local} to geocentric/geodetic, like I{.reverse}.
@arg local: Local (L{XyzLocal}, L{Enu}, L{Ned}, L{Aer} or L{Local9Tuple}). @kwarg nine: Return 3- or 9-tuple (C{bool}). @kwarg M: Include the rotation matrix (C{bool}).
@return: A I{geocentric} 3-tuple C{(x, y, z)} or if C{B{nine}=True}, an L{Ecef9Tuple}C{(x, y, z, lat, lon, height, C, M, datum)}, optionally including rotation matrix C{M} or C{None}. '''
'''Get origin's longitude (C{degrees}). '''
'''Get the rotation matrix (C{EcefMatrix}). '''
'''Reset the (geodetic) origin.
@kwarg latlonh0: Either a C{LatLon}, an L{Ecef9Tuple} or C{scalar} latitude of the origin (C{degrees}). @kwarg lon0: Optional C{scalar} longitude of the origin for C{scalar} B{C{latlonh0}} (C{degrees}). @kwarg height0: Optional origin height (C{meter}), vertically above (or below) the surface of the ellipsoid. @kwarg name: Optional, new name (C{str}).
@raise LocalError: If B{C{latlonh0}} not C{LatLon}, L{Ecef9Tuple}, C{scalar} or invalid or if B{C{lon0}} not C{scalar} for C{scalar} B{C{latlonh0}} or invalid or if B{C{height0}} invalid. '''
suffix=_0_, Error=LocalError, name=name) else: n = self.name
'''Convert I{local} C{(x, y, z)} to I{geodetic} C{(lat, lon, height)}.
@arg xyz: A I{local} (L{XyzLocal}, L{Enu}, L{Ned}, L{Aer}, L{Local9Tuple}) or local C{x} coordinate (C{scalar}). @kwarg y: Local C{y} coordinate for C{scalar} B{C{xyz}} and B{C{z}} (C{meter}). @kwarg z: Local C{z} coordinate for C{scalar} B{C{xyz}} and B{C{y}} (C{meter}). @kwarg M: Optionally, return the I{concatenated} rotation L{EcefMatrix}, I{iff avaialble} (C{bool}). @kwarg name: Optional name (C{str}).
@return: An L{Local9Tuple}C{(x, y, z, lat, lon, height, ltp, ecef, M)} with I{local} C{x}, C{y}, C{z}, I{geodetic} C{lat}, C{lon}, C{height}, this C{ltp}, an C{ecef} (L{Ecef9Tuple}) with the I{geocentric} C{x}, C{y}, C{z} (and I{geodetic} C{lat}, C{lon}, C{height}) and the I{concatenated} rotation matrix C{M} (L{EcefMatrix}) if requested.
@raise LocalError: Invalid B{C{xyz}} or C{scalar} C{x} or B{C{y}} and/or B{C{z}} not C{scalar} for C{scalar} B{C{xyz}}.
@see: Note at method L{EcefKarney.reverse}. '''
'''Return this L{LocalCartesian} as a string.
@kwarg prec: Optional precision, number of decimal digits (0..9).
@return: This L{LocalCartesian} representation (C{str}). '''
'''(INTERNAL) Get C{(x0, y0, z0)} as L{Vector3Tuple}. '''
'''A I{local tangent plan} LTP, a sub-class of C{LocalCartesian} with configurable ECEF converter and without optional rotation matrix. ''' '''New C{Ltp}.
@kwarg latlonh0: Either a C{LatLon}, L{Ltp}, L{Ecef9Tuple} or C{scalar} latitude of the (goedetic) origin (C{degrees}). @kwarg lon0: Optional C{scalar} longitude of the (goedetic) origin for C{scalar} B{C{latlonh0}} (C{degrees}). @kwarg height0: Optional origin height (C{meter}), vertically above (or below) the surface of the ellipsoid. @kwarg ecef: Optional ECEF converter (L{EcefKarney}, l{EcefFarrell21}, L{EcefFarrell22}, L{EcefSudano}, L{EcefVeness} or L{EcefYou} I{instance}), overriding default L{EcefKarney}C{(datum=Datums.WGS84)}. @kwarg name: Optional name (C{str}).
@return: New instance (C{Ltp}).
@raise LocalError: If B{C{latlonh0}} not C{LatLon}, L{Ecef9Tuple}, C{scalar} or invalid or if B{C{lon0}} not C{scalar} for C{scalar} B{C{latlonh0}} or invalid or if B{C{height0}} invalid.
@raise TypeError: Invalid B{C{ecef}}. ''' self._ecef = latlonh0.ecef self._t0 = latlonh0._to self.name = name or latlonh0.name else:
'''Get this LTP's ECEF converter (C{Ecef...} I{instance}). '''
'''Set this LTP's ECEF converter.
@arg ecef: New ECEF converter (C{Ecef...} I{instance}).
@raise TypeError: Invalid B{C{ecef}}. '''
'''A rectangular pyramid, typically representing a camera's I{field of view} (fov) and the intersection with (or projection to) a I{local tangent plane}.
@see: U{Viewing frustum<https://WikiPedia.org/wiki/Viewing_frustum>}. '''
'''New L{Frustum}.
@arg hfov: Horizontal field of view (C{degrees180}). @arg vfov: Vertical field of view (C{degrees180}). @kwarg ltp: Optional I{local tangent plane} (L{Ltp}).
@raise UnitError: Invalid B{C{hfov}} or B{C{vfov}}.
@raise ValueError: Invalid B{C{hfov}} or B{C{vfov}}. ''' raise _ValueError(hfov=hfov)
raise _ValueError(vfov=vfov)
raise _ValueError(hfov=hfov)
self._ltp = _xLtp(ltp)
'''Get the horizontal C{fov} (C{degrees}). '''
'''Compute the center and corners of the intersection with (or projection to) the I{local tangent plane} (LTP).
@arg altitude: Altitude (C{meter}) above I{local tangent plane}. @arg tilt: Pitch, elevation from horizontal (C{degrees180}), negative down. @kwarg yaw: Bearing, heading (compass C{degrees360}), clockwise from North. @kwarg roll: Roll, bank (C{degrees}), positive to the right and down. kwarg z: Optional height of the footprint (C{meter}) above I{local tangent plane}. @kwarg ltp: The I{local tangent plane} (L{Ltp}), overriding this frustum's C{ltp}.
@return: A L{Footprint5Tuple}C{(center, upperleft, upperight, loweright, lowerleft)} with the C{center} and 4 corners each an L{Xyz4Tuple}.
@raise TypeError: Invalid B{C{ltp}}.
@raise UnitError: Invalid B{C{altitude}}, B{C{tilt}}, B{C{roll}} or B{C{z}}.
@raise ValueError: If B{C{altitude}} too low, B{C{z}} too high or B{C{tilt}} or B{C{roll}} -including B{C{vfov}} respectively B{C{hfov}}- over the horizon.
@see: U{Principal axes<https://WikiPedia.org/wiki/Aircraft_principal_axes>}. ''' # left and right corners, or swapped else: # roll raise _ValueError(roll_hfov=r) raise _ValueError(tilt_vfov=t)
# rotate (x, y)'s by bearing, clockwise
raise _ValueError(altitude=altitude) z = Meter(z=z) a -= z if a < EPS: # z above a raise _ValueError(altitude_z=a) else:
raise _ValueError(tilt=tilt)
raise _ValueError(roll=r) else: # ground range raise _ValueError(tilt=tilt)
# center and corners, clockwise from upperleft, rolled + _xy2(a, t + self._v_2, -self._h_2, -self._tan_h_2, r) # swapped # turn center and corners by yaw, clockwise x, y in _xys(b, *xy5)))
'''Get the I{local tangent plane} (L{Ltp}) or C{None}. '''
'''Get the vertical C{fov} (C{degrees}). '''
'''(INTERNAL) Validate B{C{ltp}}. ''' raise _TypesError(_ltp_, ltp, Ltp, LocalCartesian)
# **) MIT License # # Copyright (C) 2016-2021 -- mrJean1 at Gmail -- All Rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. |