示例#1
0
def distance(lat1, lon1, lat2, lon2):
    """
    Compute the distance between a pair of lat/longs in meters using
    the haversine calculation. The output distance is in meters.

    Uses :func:`ichnaea._geocalc.distance` internally.
    """
    return _geocalc.distance(lat1, lon1, lat2, lon2)
示例#2
0
def _fill_bbox_cache():
    cached = []
    for country in countries:
        iso2 = _best_guess_iso_2(country)
        iso3 = _best_guess_iso_3(country)
        if not (iso2 and iso3):
            continue
        (lon1, lat1, lon2, lat2) = country.bbox
        radius = _geocalc.distance(lat1, lon1, lat2, lon2) / 2.0
        cached.append(Subunit(bbox=country.bbox,
                              alpha2=iso2.upper(),
                              alpha3=iso3.upper(),
                              radius=int(radius)))
    # sort by largest radius first
    return list(sorted(cached, key=attrgetter('radius'), reverse=True))