Ejemplo n.º 1
0
    def discrete(self, points, fraction=None):
        '''Compute only the C{forward Frechet} distance.

           @param points: Second set of points (C{LatLon}[], C{Numpy2LatLon}[],
                          C{Tuple2LatLon}[] or C{other}[]).
           @keyword fraction: Index fraction (C{float} in L{EPS}..L{EPS1}) to
                              interpolate intermediate B{C{points}} or C{None},
                              C{0} or C{1} for no I{fractional} indices and
                              intermediate B{C{points}}.

           @return: A L{Frechet6Tuple}C{(fd, fi, fj, r, n, units)}.

           @raise FrechetError: Insufficient number of B{C{points}}.

           @raise RecursionError: Recursion depth exceeded C{sys.getrecursionlimit()}.
        '''
        n2, ps2 = _points2(points, closed=False, Error=FrechetError)

        f2 = _fraction(fraction)
        p2 = self.points_fraction if f2 < EPS1 else self.points_  # PYCHOK expected

        f1 = self.fraction
        p1 = self.points_fraction if f1 < EPS1 else self.points_  # PYCHOK expected

        def dF(fi, fj):
            return self.distance(p1(self._ps1, fi), p2(ps2, fj))

        n2, ps2 = _points2(points, closed=False, Error=FrechetError)
        return _frechet_(self._n1, f1, n2, f2, dF, self.units)
Ejemplo n.º 2
0
def frechet_(points1, points2, distance=None, units=''):
    '''Compute the I{discrete} U{Frechet distance<https://WikiPedia.org/wiki/Frechet_distance>}
       between two curves given as sets of points.

       @param points1: First set of points (C{LatLon}[], C{Numpy2LatLon}[],
                       C{Tuple2LatLon}[] or C{other}[]).
       @param points2: Second set of points (C{LatLon}[], C{Numpy2LatLon}[],
                       C{Tuple2LatLon}[] or C{other}[]).
       @keyword distance: Callable returning the distance between a B{C{points1}}
                          and a B{C{points2}} point (signature C{(point1, point2)}).
       @keyword units: Optional, name of the distance units (C{str}).

       @return: A L{Frechet6Tuple}C{(fd, fi, fj, r, n, units)}.

       @raise FrechetError: Insufficient B{C{points1}} or B{C{points2}}.

       @raise RecursionError: Recursion depth exceeded C{sys.getrecursionlimit()}.

       @raise TypeError: If B{C{distance}} is not a callable.

       @note: I{Fractions}, intermediate B{C{points1}} or B{C{points2}} and
              I{fractional} indices are I{not} supported in this L{frechet_}.
    '''
    if not callable(distance):
        raise TypeError('%s not callable: %r' % ('distance', distance))

    n1, ps1 = _points2(points1, closed=False, Error=FrechetError)
    n2, ps2 = _points2(points2, closed=False, Error=FrechetError)

    def dF(i, j):
        return distance(ps1[i], ps2[j])

    return _frechet_(n1, 1, n2, 1, dF, units)
Ejemplo n.º 3
0
    def __init__(self, points, fraction=None, name='', units=''):
        '''New L{Frechet} calculator/interpolator.

           @param points: First set of points (C{LatLon}[], C{Numpy2LatLon}[],
                          C{Tuple2LatLon}[] or C{other}[]).
           @keyword fraction: Index fraction (C{float} in L{EPS}..L{EPS1}) to
                              interpolate intermediate B{C{points}} or C{None},
                              C{0} or C{1} for no I{fractional} indices and
                              intermediate B{C{points}}.
           @keyword name: Optional calculator name (C{str}).
           @keyword units: Optional, distance units (C{str}).

           @raise FrechetError: Insufficient number of B{C{points1}} or
                                invalid B{C{fraction}}.
        '''
        self._n1, self._ps1 = _points2(points,
                                       closed=False,
                                       Error=FrechetError)
        if fraction:
            self.fraction = fraction
        if name:
            self.name = name
        if units:
            self.units = units