Python geopy.distance 模块,distance() 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用geopy.distance.distance()

项目:sahaf    作者:EmreYavuz216    | 项目源码 | 文件源码
def distance(self,obj):
        if 'location' in self.context.keys():
            request = self.context['request']
            tuple_x_y  = (float(request.query_params['Latitude']),float(request.query_params['Longitude']))
            point = Point(tuple_x_y,srid=4326)
            result = distance(obj.Point,point).km
            if result < 5:
                return '5 km içerisinde'
            elif result > 5 and result < 10:
                return '10 km içerisinde'
            elif result > 10 and result < 25:
                return '25 km içerisinde'
            elif result > 25 and result < 50:
                return '50 km içerisinde'
            else:
                return obj.City + ' çevresinde'
        return obj.City + ' çevresinde'
项目:perdiem-django    作者:RevolutionTech    | 项目源码 | 文件源码
def filter_by_location(self, distance, lat, lon):
        min_lat, max_lat, min_lon, max_lon = self.bounding_coordinates(distance, lat, lon)
        artists_within_bounds = self.filter(
            lat__gte=min_lat,
            lat__lte=max_lat,
            lon__gte=min_lon,
            lon__lte=max_lon
        )

        nearby_artist_ids = []
        for artist in artists_within_bounds:
            if calc_distance((lat, lon,), (artist.lat, artist.lon,)).miles <= distance:
                nearby_artist_ids.append(artist.id)
        return self.filter(id__in=nearby_artist_ids)

    # TODO(lucas): Use annotations as much as possible to improve performance
项目:Monocle    作者:Noctem    | 项目源码 | 文件源码
def get_gains(dist=70):
    """Returns lat and lon gain

    Gain is space between circles.
    """
    start = Point(*bounds.center)
    base = dist * sqrt(3)
    height = base * sqrt(3) / 2
    dis_a = distance(meters=base)
    dis_h = distance(meters=height)
    lon_gain = dis_a.destination(point=start, bearing=90).longitude
    lat_gain = dis_h.destination(point=start, bearing=0).latitude
    return abs(start.latitude - lat_gain), abs(start.longitude - lon_gain)
项目:PopMap    作者:tuvtran    | 项目源码 | 文件源码
def closest(self, graph):
        valid_nodes = self.closer_nodes(graph)
        best_dist = None
        best = None
        for other in valid_nodes:
            dist = distance.distance(self.pt, other.pt).meters
            if not best_dist or dist < best_dist:
                best_dist = dist
                best = other
        return best
项目:strans-pyra    作者:teresinahc    | 项目源码 | 文件源码
def nearest(cls, lat, long, **kwargs):
        """
        Search for the nearest stop from `lat` and `long`
        params.

        You should specify the stops to search, default is
        `Stop.all()`.

        @param lat: A float coercible value of latitude (eg.: -5.065533).
        @param long: A float coercible value of longitude (eg.: -42.065533).

        keywords params:
            stops:
                A list of `Stop` instance.
            route:
                A `Route` instance.

        @return: A tuple with a `Stop` object and a `Distance`
            object (see geopy.distance).
        """

        if kwargs.get('stops', False):
            stops = kwargs['stops']
        elif kwargs.get('route', False):
            stops = kwargs['route'].get_stops()
        else:
            stops = cls.all()

        dists = map(lambda stop: distance(
                (stop.lat, stop.long),
                (lat, long)
            ), stops)

        return min(zip(dists, stops))[::-1]
项目:strans-pyra    作者:teresinahc    | 项目源码 | 文件源码
def nearest(cls, lat, long, **kwargs):
        """
        Search for the nearest buses from `lat` and `long`
        params.

        You should specify the buses to search, default is
        `Buses.all()`.

        @param lat: A float coercible value of latitude (eg.: -5.065533).
        @param long: A float coercible value of longitude (eg.: -42.065533).

        keywords params:
            buses:
                A list of `Stop` instance.
            route:
                A `Route` instance.

        @return: A tuple with a `Bus` object and a `Distance`
            object (see geopy.distance).
        """
        if kwargs.get('buses', False):
            buses = kwargs['buses']
        elif kwargs.get('route', False):
            buses = kwargs['route'].get_buses()
        else:
            buses = cls.all()

        dists = map(lambda bus: distance(
                # Avoid using cached location, to avoid more requests.
                (bus.__lat__, bus.__long__),
                (lat, long)
            ), buses)

        return min(zip(dists, buses))[::-1]
项目:perdiem-django    作者:RevolutionTech    | 项目源码 | 文件源码
def bounding_coordinates(distance, lat, lon):
        origin = geopy.Point((lat, lon,))
        geopy_distance = calc_distance(miles=distance)
        min_lat = geopy_distance.destination(origin, 180).latitude
        max_lat = geopy_distance.destination(origin, 0).latitude
        min_lon = geopy_distance.destination(origin, 270).longitude
        max_lon = geopy_distance.destination(origin, 90).longitude
        return min_lat, max_lat, min_lon, max_lon
项目:strans-pyra    作者:teresinahc    | 项目源码 | 文件源码
def traceroute(self, source, dest):
        """
        Trace a route between `source` and `dest`.

        First, find the nearest stop to `source` and the nearest to `dest`
        and try to find a common route to both. Otherwise, fallbacks searching
        for all routes of the `source` stop and `dest` stop, choosing the one
        what is nearest to the `source` or `dest`.

        @param source: a pair latitude and longitude
        @param dest: a pair latitude and longitude

        @return: a tuple like ((<source stop>, <distance to the nearest stop>),
            (<dest stop>, <distance to the nearest stop>), <route>)
        """

        sourcestop, dsrc = Stop.nearest(source[0], source[1])
        deststop, ddst = Stop.nearest(dest[0], dest[1])
        sourceroutes = sourcestop.get_routes()
        destroutes = deststop.get_routes()

        for i, j in itertools.product(sourceroutes, destroutes):
            if i == j:
                return (sourcestop, dsrc), (deststop, ddst), i

        dist, stop, route = min(
            min(
                Stop.nearest(
                    source[0],
                    source[1],
                    route=route
                )[::-1] + (route,) for route in destroutes
            ),
            min(
                Stop.nearest(
                    dest[0],
                    dest[1],
                    route=route
                )[::-1] + (route,) for route in sourceroutes
            )
        )

        sourcestop = Stop.nearest(source[0], source[1], route=route)
        deststop = Stop.nearest(dest[0], dest[1], route=route)

        return sourcestop, deststop, route