예제 #1
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: a map scale - the 'n' in '1/n', eg., 19200

    Returns a list of bunches.
    """
    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
예제 #2
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)
예제 #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: a map scale - the 'n' in '1/n', eg., 19200

    Returns a list of bunches.
    """
    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
예제 #5
0
 def set_resolutions(self, scales, units=None):
     if units is None:
         units = self.units
     self.resolutions = [get_resolution(s, units) for s in scales]
예제 #6
0
파일: tile.py 프로젝트: frankk00/openblock
 def set_resolutions(self, scales, units=None):
     if units is None:
         units = self.units
     self.resolutions = [get_resolution(s, units) for s in scales]