Package mapproxy :: Package core :: Module grid :: Class TileGrid
[hide private]
[frames] | no frames]

Class TileGrid

source code

object --+
         |
        TileGrid

This class represents a regular tile grid. The first level (0) contains a single tile, the origin is bottom-left.
Instance Methods [hide private]
 
__init__(self, epsg=900913, bbox=None, tile_size=(256, 256), res=None, is_geodetic=False, levels=None)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
_calc_grids(self) source code
 
_calc_bbox(self) source code
 
_calc_res(self, factor=None) source code
 
resolution(self, level)
Returns the resolution of the level in units/pixel.
source code
 
closest_level(self, res)
Returns the level index that offers the required resolution.
source code
 
tile(self, x, y, level)
Returns the tile id for the given point.
source code
 
flip_tile_coord(self, (x, y, z))
Flip the tile coord on the y-axis.
source code
bbox, (xs, yz), [(x, y, z), ...]
get_affected_tiles(self, bbox, size, req_srs=None, inverse=False)
Get a list with all affected tiles for a bbox and output size.
source code
 
get_affected_bbox_and_level(self, bbox, size, req_srs=None) source code
 
get_affected_level_tiles(self, bbox, level, inverse=False)
Get a list with all affected tiles for a bbox in the given level.
source code
 
_tile_iter(self, x0, y0, x1, y1, level, inverse=False) source code
 
_get_bbox(self, tiles)
Returns the bbox of multiple tiles.
source code
 
_get_south_west_point(self, tile_coord)
Returns the coordinate of the lower left corner.
source code
 
tile_bbox(self, (x, y, z))
Returns the bbox of the given tile.
source code
 
limit_tile(self, tile_coord)
Check if the tile_coord is in the grid.
source code
 
__repr__(self)
repr(x)
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __str__

Class Variables [hide private]
  spheroid_a = 6378137.0
Instance Variables [hide private]
  stretch_factor
allow images to be scaled up by this factor before the next level will be selected
  max_shrink_factor
allow images to be scaled down by this factor before NoTiles is raised
  bbox
the bbox of the grid, tiles may overlap this bbox
  levels
the number of levels
RES_TYPE_CUSTOM, RES_TYPE_GLOBAL, RES_TYPE_SQRT2 res_type
the type of the multi-resolution pyramid.
SRS srs
the srs of the grid
int(with), int(height) tile_size
the size of each tile in pixel
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, epsg=900913, bbox=None, tile_size=(256, 256), res=None, is_geodetic=False, levels=None)
(Constructor)

source code 
>>> grid = TileGrid(epsg=900913)
>>> [round(x, 2) for x in grid.bbox]
[-20037508.34, -20037508.34, 20037508.34, 20037508.34]
Overrides: object.__init__

resolution(self, level)

source code 

Returns the resolution of the level in units/pixel.

>>> grid = TileGrid(epsg=900913)
>>> grid.resolution(0)
156543.03392804097
>>> grid.resolution(1)
78271.516964020484
>>> grid.resolution(4)
9783.9396205025605
Parameters:
  • level - the zoom level index (zero is top)

closest_level(self, res)

source code 

Returns the level index that offers the required resolution.

>>> grid = TileGrid(epsg=900913)
>>> grid.stretch_factor = 1.1
>>> l1_res = grid.resolution(1)
>>> [grid.closest_level(x) for x in (320000.0, 160000.0, l1_res+50, l1_res,                                              l1_res-50, l1_res*0.91, l1_res*0.89, 8000.0)]
[0, 0, 1, 1, 1, 1, 2, 5]
Parameters:
  • res - the required resolution
Returns:
the level with the requested or higher resolution

flip_tile_coord(self, (x, y, z))

source code 

Flip the tile coord on the y-axis. (Switch between bottom-left and top-left origin.)

>>> grid = TileGrid(epsg=900913)
>>> grid.flip_tile_coord((0, 1, 1))
(0, 0, 1)
>>> grid.flip_tile_coord((1, 3, 2))
(1, 0, 2)

get_affected_tiles(self, bbox, size, req_srs=None, inverse=False)

source code 

Get a list with all affected tiles for a bbox and output size.

>>> grid = TileGrid()
>>> bbox = (-20037508.34, -20037508.34, 20037508.34, 20037508.34)
>>> tile_size = (256, 256)
>>> grid.get_affected_tiles(bbox, tile_size)
... #doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
((-20037508.342789244, -20037508.342789244,          20037508.342789244, 20037508.342789244), (1, 1),          <generator object ...>)
Returns: bbox, (xs, yz), [(x, y, z), ...]
the bbox, the size and a list with tile coordinates, sorted row-wise

get_affected_level_tiles(self, bbox, level, inverse=False)

source code 

Get a list with all affected tiles for a bbox in the given level. :returns: the bbox, the size and a list with tile coordinates, sorted row-wise :rtype: bbox, (xs, yz), [(x, y, z), ...]

>>> grid = TileGrid()
>>> bbox = (-20037508.34, -20037508.34, 20037508.34, 20037508.34)
>>> grid.get_affected_level_tiles(bbox, 0)
... #doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
((-20037508.342789244, -20037508.342789244,          20037508.342789244, 20037508.342789244), (1, 1),          <generator object ...>)

_get_bbox(self, tiles)

source code 
Returns the bbox of multiple tiles. The tiles should be ordered row-wise, bottom-up.
Parameters:
  • tiles - ordered list of tiles
Returns:
the bbox of all tiles

_get_south_west_point(self, tile_coord)

source code 

Returns the coordinate of the lower left corner.

>>> grid = TileGrid(epsg=900913)
>>> [round(x, 2) for x in grid._get_south_west_point((0, 0, 0))]
[-20037508.34, -20037508.34]
>>> [round(x, 2) for x in grid._get_south_west_point((1, 1, 1))]
[0.0, 0.0]
Parameters:
  • tile_coord ((x, y, z)) - the tile coordinate

limit_tile(self, tile_coord)

source code 

Check if the tile_coord is in the grid.

>>> grid = TileGrid(epsg=900913)
>>> grid.limit_tile((-1, 0, 2)) == None
True
>>> grid.limit_tile((1, 2, 1)) == None
True
>>> grid.limit_tile((1, 2, 2))
(1, 2, 2)
Returns:
the tile_coord if it is within the grid, otherwise None.

__repr__(self)
(Representation operator)

source code 
repr(x)
Overrides: object.__repr__
(inherited documentation)