Example #1
0
def geohash_haversine_distance(geohash_1, geohash_2):
    """
    converts the geohashes to lat/lon and then calculates the haversine great circle distance in meters.

    :param geohash_1:
    :param geohash_2:
    :return:
    """

    lat_1, lon_1 = decode(geohash_1)
    lat_2, lon_2 = decode(geohash_2)

    R = 6371000
    phi_1 = math.radians(lat_1)
    phi_2 = math.radians(lat_2)

    delta_phi = math.radians(lat_2 - lat_1)
    delta_lambda = math.radians(lon_2 - lon_1)

    a = math.sin(delta_phi / 2.0) * math.sin(delta_phi / 2.0) + math.cos(phi_1) * math.cos(phi_2) * math.sin(
        delta_lambda / 2
    ) * math.sin(delta_lambda / 2)
    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))

    return R * c
def geohash_haversine_distance(geohash_1, geohash_2):
    """
    converts the geohashes to lat/lon and then calculates the haversine great circle distance in meters.

    :param geohash_1:
    :param geohash_2:
    :return:
    """

    lat_1, lon_1 = decode(geohash_1)
    lat_2, lon_2 = decode(geohash_2)

    R = 6371000
    phi_1 = math.radians(lat_1)
    phi_2 = math.radians(lat_2)

    delta_phi = math.radians(lat_2 - lat_1)
    delta_lambda = math.radians(lon_2 - lon_1)

    a = math.sin(delta_phi / 2.0) * math.sin(
        delta_phi / 2.0) + math.cos(phi_1) * math.cos(phi_2) * math.sin(
            delta_lambda / 2) * math.sin(delta_lambda / 2)
    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))

    return R * c
Example #3
0
def southern(geohashes):
    """
    Takes in an iterable of geohashes and returns the southernmost position of the group as a geohash.

    :param geohashes:
    :return:
    """

    latlons = [decode(x) for x in geohashes]
    latlons = sorted(latlons, key=lambda x: x[0], reverse=False)
    return encode(latlons[0][0], latlons[0][1])
Example #4
0
def mean(geohashes):
    """
    Takes in an iterable of geohashes and returns the mean position of the group as a geohash.

    :param geohashes:
    :return:
    """

    latlons = [decode(x) for x in geohashes]
    count = len(latlons)
    return encode(float(sum([x[0] for x in latlons])) / count, float(sum([x[1] for x in latlons])) / count)
def southern(geohashes):
    """
    Takes in an iterable of geohashes and returns the southernmost position of the group as a geohash.

    :param geohashes:
    :return:
    """

    latlons = [decode(x) for x in geohashes]
    latlons = sorted(latlons, key=lambda x: x[0], reverse=False)
    return encode(latlons[0][0], latlons[0][1])
def mean(geohashes):
    """
    Takes in an iterable of geohashes and returns the mean position of the group as a geohash.

    :param geohashes:
    :return:
    """

    latlons = [decode(x) for x in geohashes]
    count = len(latlons)
    return encode(float(sum([x[0] for x in latlons])) / count, float(sum([x[1] for x in latlons])) / count)
Example #7
0
"""
Example #8
0
"""