Пример #1
0
def buffer_extent(extent, zoom_level, num_tiles=6, tile_size=256, units='degrees'):
    """
    Buffers an extent by the size of num_tiles at a particular zoom level.
    """
    scale = settings.MAP_SCALES[zoom_level]
    resolution = get_resolution(scale, units)
    ll_px = px_from_lnglat((extent[0], extent[1]), resolution)
    ur_px = px_from_lnglat((extent[2], extent[3]), resolution)
    pixel_buf = num_tiles * tile_size
    # Note that the (0, 0) point for the lnglat_from_px function is upper-left,
    # so /addition/ of the buffer to the y component moves it in the negative
    # direction, and vice versa
    ll_px = (ll_px[0] - pixel_buf, ll_px[1] + pixel_buf)
    ur_px = (ur_px[0] + pixel_buf, ur_px[1] - pixel_buf)
    return lnglat_from_px(ll_px, resolution) + lnglat_from_px(ur_px, resolution)
Пример #2
0
def cluster_by_scale(objs,
                     radius,
                     scale,
                     extent=(-180, -90, 180, 90),
                     cluster_fn=cluster.buffer_cluster):
    """
    Required parameters:

        + objs: dict, keys to ID objects, values are point 2-tuples
        + radius: in pixels
        + scale: 'n' in '1/n', eg., 19200
    """
    resolution = get_resolution(scale)

    # Translate from lng/lat into coordinate system of the display.
    objs = dict([(k, px_from_lnglat(v, resolution, extent))
                 for k, v in objs.iteritems()])

    bunches = []
    for bunch in cluster_fn(objs, radius):
        # Translate back into lng/lat.
        bunch.center = lnglat_from_px(bunch.center, resolution, extent)
        bunches.append(bunch)

    return bunches
Пример #3
0
def buffer_extent(extent,
                  zoom_level,
                  num_tiles=6,
                  tile_size=256,
                  units='degrees'):
    """
    Buffers an extent by the size of num_tiles at a particular zoom level.
    """
    scale = settings.MAP_SCALES[zoom_level]
    resolution = get_resolution(scale, units)
    ll_px = px_from_lnglat((extent[0], extent[1]), resolution)
    ur_px = px_from_lnglat((extent[2], extent[3]), resolution)
    pixel_buf = num_tiles * tile_size
    # Note that the (0, 0) point for the lnglat_from_px function is upper-left,
    # so /addition/ of the buffer to the y component moves it in the negative
    # direction, and vice versa
    ll_px = (ll_px[0] - pixel_buf, ll_px[1] + pixel_buf)
    ur_px = (ur_px[0] + pixel_buf, ur_px[1] - pixel_buf)
    return lnglat_from_px(ll_px, resolution) + lnglat_from_px(
        ur_px, resolution)
Пример #4
0
def cluster_by_scale(objs, radius, scale, extent=(-180, -90, 180, 90),
                     cluster_fn=cluster.buffer_cluster):
    """
    Required parameters:

        + objs: dict, keys to ID objects, values are point 2-tuples
        + radius: in pixels
        + scale: 'n' in '1/n', eg., 19200
    """
    resolution = get_resolution(scale)

    # Translate from lng/lat into coordinate system of the display.
    objs = dict([(k, px_from_lnglat(v, resolution, extent)) for k, v in objs.iteritems()])

    bunches = []
    for bunch in cluster_fn(objs, radius):
        # Translate back into lng/lat.
        bunch.center = lnglat_from_px(bunch.center, resolution, extent)
        bunches.append(bunch)

    return bunches