def _update(self, updated): '''(INTERNAL) Clear caches if updated. ''' if updated: # reset caches self._Nv = self._r3 = None LatLonNvectorBase._update(self, updated) LatLonEllipsoidalBase._update(self, updated)
def copy(self): '''Copy this point. @return: Copy of this point (L{LatLon}). ''' p = LatLonEllipsoidalBase.copy(self) assert hasattr(p, 'epsilon') p.epsilon = self.epsilon assert hasattr(p, 'iterations') p.iterations = self.iterations return p
def equals(self, other, eps=None): '''Check if this point is equal to an other point. @param other: The other point (L{LatLon}). @keyword eps: Optional margin (float). @return: True if points are identical (bool). @raise TypeError: The other point is not L{LatLon}. @example: >>> p = LatLon(52.205, 0.119) >>> q = LatLon(52.205, 0.119) >>> e = p.equals(q) # True ''' return LatLonEllipsoidalBase.equals(self, other, eps=eps) and \ self.height == other.height and self.datum == other.datum
def isequalTo(self, other, eps=None): '''Compare this point with an other point. @param other: The other point (L{LatLon}). @keyword eps: Optional margin (C{float}). @return: C{True} if points are identical, including datum, I{ignoring height}, C{False} otherwise. @raise TypeError: The I{other} point is not L{LatLon}. @see: Use method L{isequalTo3} to include I{height}. @example: >>> p = LatLon(52.205, 0.119) >>> q = LatLon(52.205, 0.119) >>> e = p.isequalTo(q) # True ''' return LatLonEllipsoidalBase.isequalTo(self, other, eps=eps) \ and self.datum == other.datum
def equals(self, other, eps=None): '''Compare this point with an other point. @param other: The other point (L{LatLon}). @keyword eps: Optional margin (float). @return: True if points are identical, including datum, I{ignoring height} (bool). @raise TypeError: The I{other} point is not L{LatLon}. @see: Use method L{equals3} to include height. @example: >>> p = LatLon(52.205, 0.119) >>> q = LatLon(52.205, 0.119) >>> e = p.equals(q) # True ''' return LatLonEllipsoidalBase.equals(self, other, eps=eps) \ and self.datum == other.datum
def _xcopy(self, *attrs): '''(INTERNAL) Make copy with add'l, subclass attributes. ''' return LatLonEllipsoidalBase._xcopy(self, '_epsilon', '_iterations', *attrs)
def toOsgr(latlon, lon=None, datum=Datums.WGS84): '''Convert lat-/longitude to a OSGR coordinate. @param latlon: Latitude in degrees (scalar) or an ellipsoidal LatLon location. @keyword lon: Longitude in degrees (scalar or None). @keyword datum: Datum to use (L{Datum}). @return: The OSGR coordinate (L{Osgr}). @raise TypeError: If latlon is not ellipsoidal. @raise ValueError: If lon is invalid, not None. @example: >>> p = LatLon(52.65798, 1.71605) >>> r = toOsgr(p) # TG 51409 13177 >>> # for conversion of (historical) OSGB36 lat-/longitude: >>> r = toOsgr(52.65757, 1.71791, datum=Datums.OSGB36) ''' if isscalar(latlon) and isscalar(lon): # XXX any ellipsoidal LatLon with .convertDatum latlon = LatLonEllipsoidalBase(latlon, lon, datum=datum) elif not hasattr(latlon, 'convertDatum'): raise TypeError('%s not ellipsoidal: %r' % ('latlon', latlon)) elif lon is not None: raise ValueError('%s not %s: %r' % ('lon', None, lon)) if latlon.datum != _OSGB36: latlon = latlon.convertDatum(_OSGB36) E = _OSGB36.ellipsoid a, b = radians(latlon.lat), radians(latlon.lon) ca, sa, ta = cos(a), sin(a), tan(a) s = 1 - E.e2 * sa * sa v = E.a * _F0 / sqrt(s) r = s / E.e12 # = v / r = v / (v * E.e12 / s) ca3 = ca * ca * ca ca5 = ca * ca * ca3 ta2 = ta * ta ta4 = ta2 * ta2 x2 = r - 1 # η I4 = (E.b * _M(E.Mabcd, a) + _N0, (v / 2) * sa * ca, (v / 24) * sa * ca3 * (5 - ta2 + 9 * x2), (v / 720) * sa * ca5 * (61 - 58 * ta2 + ta4)) V4 = (_E0, v * ca, (v / 6) * ca3 * (r - ta2), (v / 120) * ca5 * (5 - 18 * ta2 + ta4 + 14 * x2 - 58 * ta2 * x2)) d = b - _B0 d2 = d * d d3 = d2 * d d5 = d2 * d3 n = fdot(I4, 1, d2, d3 * d, d5 * d) e = fdot(V4, 1, d, d3, d5) return Osgr(e, n)