Example #1
0
    def test_compress(self):
        geohashes = set(['tdnu20', 'tdnu21', 'tdnu22', 'tdnu23', 'tdnu24', 'tdnu25', 'tdnu26', 'tdnu27', 'tdnu28', 'tdnu29',
                     'tdnu2b', 'tdnu2c', 'tdnu2d', 'tdnu2e', 'tdnu2f', 'tdnu2g', 'tdnu2h', 'tdnu2j', 'tdnu2k', 'tdnu2m',
                     'tdnu2n', 'tdnu2p', 'tdnu2q', 'tdnu2r', 'tdnu2s', 'tdnu2t', 'tdnu2u', 'tdnu2v', 'tdnu2w', 'tdnu2x',
                     'tdnu2y', 'tdnu2z'])
        final_geohash = set(['tdnu2'])

        output = georaptor.compress(geohashes)
        self.assertEqual(output, final_geohash)
Example #2
0
def create_geohash(latitude, longitude, radius, precision, georaptor_flag=False, minlevel=1, maxlevel=12):

    x = 0.0
    y = 0.0

    points = []
    geohashes = []

    grid_width = [5009400.0, 1252300.0, 156500.0, 39100.0, 4900.0, 1200.0, 152.9, 38.2, 4.8, 1.2, 0.149, 0.0370]
    grid_height = [4992600.0, 624100.0, 156000.0, 19500.0, 4900.0, 609.4, 152.4, 19.0, 4.8, 0.595, 0.149, 0.0199]

    height = (grid_height[precision - 1])/2
    width = (grid_width[precision-1])/2

    lat_moves = int(math.ceil(radius / height)) #4
    lon_moves = int(math.ceil(radius / width)) #2

    for i in range(0, lat_moves):

        temp_lat = y + height*i

        for j in range(0,lon_moves):

            temp_lon = x + width*j

            if in_circle_check(temp_lat, temp_lon, y, x, radius):

                x_cen, y_cen = get_centroid(temp_lat, temp_lon, height, width)

                lat, lon = convert_to_latlon(y_cen, x_cen, latitude, longitude)
                points += [[lat, lon]]
                lat, lon = convert_to_latlon(-y_cen, x_cen, latitude, longitude)
                points += [[lat, lon]]
                lat, lon = convert_to_latlon(y_cen, -x_cen, latitude, longitude)
                points += [[lat, lon]]
                lat, lon = convert_to_latlon(-y_cen, -x_cen, latitude, longitude)
                points += [[lat, lon]]


    for point in points:
        geohashes += [Geohash.encode(point[0], point[1], precision)]

    if georaptor_flag:
        georaptor_out = georaptor.compress(set(geohashes), int(minlevel), int(maxlevel))
        return ','.join(georaptor_out)

    else:
        return ','.join(set(geohashes))
Example #3
0
def get_geohash_radius_approximation(latitude,
                                     longitude,
                                     radius,
                                     precision,
                                     georaptor_flag=False,
                                     minlevel=1,
                                     maxlevel=12):
    """
    Get the list of geohashed that approximate a circle
    :param latitude: Float the longitude to get the radius approximation for
    :param longitude: Float  the latitude to get the radius approximation for
    :param radius:  Integer Radius coverage in meters
    :param precision: Integer the geohash precision level
    :param georaptor_flag: Do you want to compress it with georaptor
    :param minlevel: minimal precision level possible
    :param maxlevel: maximal precision level possible
    :return: A list of geohashes
    """

    x = 0.0
    y = 0.0

    points = []
    geohashes = []

    grid_width = [
        5009400.0, 1252300.0, 156500.0, 39100.0, 4900.0, 1200.0, 152.9, 38.2,
        4.8, 1.2, 0.149, 0.0370
    ]
    grid_height = [
        4992600.0, 624100.0, 156000.0, 19500.0, 4900.0, 609.4, 152.4, 19.0,
        4.8, 0.595, 0.149, 0.0199
    ]

    height = (grid_height[precision - 1]) / 2
    width = (grid_width[precision - 1]) / 2

    lat_moves = int(math.ceil(radius / height))  # 4
    lon_moves = int(math.ceil(radius / width))  # 2

    for i in range(0, lat_moves):

        temp_lat = y + height * i

        for j in range(0, lon_moves):

            temp_lon = x + width * j

            if in_circle_check(temp_lat, temp_lon, y, x, radius):
                x_cen, y_cen = get_centroid(temp_lat, temp_lon, height, width)

                lat, lon = convert_to_latlon(y_cen, x_cen, latitude, longitude)
                points += [[lat, lon]]
                lat, lon = convert_to_latlon(-y_cen, x_cen, latitude,
                                             longitude)
                points += [[lat, lon]]
                lat, lon = convert_to_latlon(y_cen, -x_cen, latitude,
                                             longitude)
                points += [[lat, lon]]
                lat, lon = convert_to_latlon(-y_cen, -x_cen, latitude,
                                             longitude)
                points += [[lat, lon]]

    for point in points:
        geohashes += [pgh.encode(point[0], point[1], precision)]

    if georaptor_flag:
        georaptor_out = georaptor.compress(set(geohashes), int(minlevel),
                                           int(maxlevel))
        return list(georaptor_out)

    else:
        return list(set(geohashes))