Ejemplo n.º 1
0
def get_citywide_bounds_for_size(city_slug, size=LOCATOR_SIZE):
    """
    Returns a 4-tuple extent in degrees decimal longitude and latitude
    the extent of a rectangle in (size[0], size[1]) pixels that is
    filled by the city.

    This is useful in generating locator map bounds because the extent
    of the city doesn't typically match the aspect ratio of the image.
    """
    extent = city_extent_in_map_srs(city_slug)
    resolution = extent_resolution(extent, size, settings.MAP_UNITS)
    new_extent = calculate_bounds(center(extent), resolution, size)
    # Convert back to lng/lat
    return transform_extent(new_extent, 4326, src_srs=900913)
Ejemplo n.º 2
0
def get_citywide_bounds_for_size(city_slug, size=LOCATOR_SIZE):
    """
    Returns a 4-tuple extent in degrees decimal longitude and latitude
    the extent of a rectangle in (size[0], size[1]) pixels that is
    filled by the city.

    This is useful in generating locator map bounds because the extent
    of the city doesn't typically match the aspect ratio of the image.
    """
    extent = city_extent_in_map_srs(city_slug)
    resolution = extent_resolution(extent, size, settings.MAP_UNITS)
    new_extent = calculate_bounds(center(extent), resolution, size)
    # Convert back to lng/lat
    return transform_extent(new_extent, 4326, src_srs=900913)
Ejemplo n.º 3
0
def cover_region(extent, radius):
    """
    Returns an iterator that covers a given region with circle buffer of given
    radius. `extent` should be given in terms of lat/lng, and `radius` should be
    in kilometers.

    The iterator yields (lng, lat) tuples -- the centroid of the buffer.
    """
    target_srs = 900913 # Spherical Mercator

    # Convert radius from km to meters
    radius_m = radius * 1000

    # Convert extent from lat/lng to a projected extent
    proj_ext = transform_extent(extent, target_srs)

    for (x, y) in tessellate(proj_ext, radius_m):
        pt = Point(x, y, srid=target_srs)
        pt.transform(4326)
        yield (pt.x, pt.y)
Ejemplo n.º 4
0
def get_all_tile_coords(layer, cities=None, levels=(0, 5)):
    """
    A shortcut for getting all the tile coordinates for a layer.

    Can be optionally constrained by city or a list of cities (slugs).
    """
    if isinstance(layer, basestring):
        layer = get_eb_layer(layer)

    if cities is None:
        cities = METRO_DICT.keys()
    elif isinstance(cities, basestring):
        cities = [cities]

    for slug in cities:
        bboxes = []
        city_ext = transform_extent(get_metro(slug)['extent'], layer.dest_srs)
        for level in xrange(*levels):
            bboxes.append(buffer_extent(city_ext, level, units=settings.MAP_UNITS))
        for tile_coords in get_tile_coords(layer, levels=levels, bboxes=bboxes):
            yield tile_coords
Ejemplo n.º 5
0
 def set_bbox(self, bbox):
     self.bbox = transform_extent(bbox, self.dest_srs)
Ejemplo n.º 6
0
def extent_in_map_srs(extent):
    """
    Returns an extent assumed to be in lng/lat in the target map SRS
    """
    return transform_extent(extent, settings.SPATIAL_REF_SYS)
Ejemplo n.º 7
0
def get_locator_scale(city_slug, size=(75,75)):
    bbox = transform_extent(get_metro(city_slug)['extent'], settings.SPATIAL_REF_SYS)
    return extent_scale(bbox, size, settings.MAP_UNITS)
Ejemplo n.º 8
0
 def set_bbox(self, bbox):
     self.bbox = transform_extent(bbox, self.dest_srs)