def d2yxu(self, i, j): '''Return distance squared, points[i] to -[j] deltas and longitudinal unrollment. ''' p1 = self.pts[i] p2 = self.pts[j] return equirectangular_(p1.lat, p1.lon, p2.lat, p2.lon, **self.options)
def distance2To(self, other, radius=R_M, adjust=False, wrap=False): '''Compute the distance between this and an other geohash using the U{Equirectangular Approximation / Projection <http://www.Movable-Type.co.UK/scripts/latlong.html>}. @param other: The other geohash (L{Geohash}). @keyword radius: Optional, mean earth radius (C{meter}) or C{None}. @keyword adjust: Adjust the wrapped, unrolled longitudinal delta by the cosine of the mean latitude (C{bool}). @keyword wrap: Wrap and unroll longitudes (C{bool}). @return: Approximate distance (C{meter}, same units as I{radius}) or distance squared (C{degrees} squared) if I{radius} is C{None} or 0. @raise TypeError: The I{other} is not a L{Geohash}, C{LatLon} or C{str}. @see: U{Local, flat earth approximation <http://www.EdWilliams.org/avform.htm#flat>}, functions ''' other = _2Geohash(other) a1, b1 = self.latlon a2, b2 = other.latlon if radius: return equirectangular(a1, b1, a2, b2, radius=radius, adjust=adjust, limit=None, wrap=wrap) else: return equirectangular_(a1, b1, a2, b2, adjust=adjust, limit=None, wrap=wrap)[0]
def equirectangular3(lat1, lon1, lat2, lon2, **options): '''DEPRECATED, use function C{equirectangular_}. @return: 3-Tuple C{(distance2, delta_lat, delta_lon)}. ''' from formy import equirectangular_ return tuple(equirectangular_(lat1, lon1, lat2, lon2, **options)[:3])
def _d2yx(p2, p1, u, i): w = wrap if (not closed or i < (n - 1)) else False # equirectangular_ returns a 4-tuple (distance in # degrees squared, delta lat, delta lon, p2.lon # unroll/wrap); the previous p2.lon unroll/wrap # is also applied to the next edge's p1.lon return equirectangular_(p1.lat, p1.lon + u, p2.lat, p2.lon, wrap=w, **options)
def _degs(n, pts, closed): # angular edge lengths in degrees i, m = _imdex2(closed, n) x1, y1, _ = pts[i] u = 0 # previous x2's unroll/wrap for i in range(m, n): x2, y2, _ = pts[i] w = wrap if (not closed or i < (n - 1)) else False # apply previous x2's unroll/wrap to new x1 _, dy, dx, u = equirectangular_(y1, x1 + u, y2, x2, adjust=adjust, limit=None, wrap=w) yield hypot(dx, dy) x1, y1 = x2, y2
def equirectangular3(lat1, lon1, lat2, lon2, **options): '''DEPRECATED, use function I{equirectangular_}. @return: 3-Tuple (distance2, delta_lat, delta_lon). ''' return formy.equirectangular_(lat1, lon1, lat2, lon2, **options)[:3]