datacube.model.GridSpec

class datacube.model.GridSpec(crs, tile_size, resolution, origin=None)[source]

Definition for a regular spatial grid.

>>> gs = GridSpec(crs=geometry.CRS('EPSG:4326'), tile_size=(1, 1),
    resolution=(-0.1, 0.1), origin=(-50.05, 139.95))
>>> gs.tile_resolution
(10, 10)
>>> list(gs.tiles(geometry.BoundingBox(140, -50, 141.5, -48.5)))
[((0, 0), GeoBox(10, 10, Affine(0.1, 0.0, 139.95,
    0.0, -0.1, -49.05), EPSG:4326)), ((1, 0), GeoBox(10, 10, Affine(0.1, 0.0, 140.95,
    0.0, -0.1, -49.05), EPSG:4326)), ((0, 1), GeoBox(10, 10, Affine(0.1, 0.0, 139.95,
    0.0, -0.1, -48.05), EPSG:4326)), ((1, 1), GeoBox(10, 10, Affine(0.1, 0.0, 140.95,
    0.0, -0.1, -48.05), EPSG:4326))]

Create a GridSpec.

Parameters
  • crs (geometry.CRS) – Coordinate System used to define the grid

  • tile_size (Tuple[float, float]) – (Y, X) size of each tile, in CRS units

  • resolution (Tuple[float, float]) – (Y, X) size of each data point in the grid, in CRS units. Y will usually be negative.

  • origin (Optional[Tuple[float, float]]) – (Y, X) coordinates of a corner of the (0,0) tile in CRS units. default is (0.0, 0.0)

__init__(crs, tile_size, resolution, origin=None)[source]

Create a GridSpec.

Parameters
  • crs (geometry.CRS) – Coordinate System used to define the grid

  • tile_size (Tuple[float, float]) – (Y, X) size of each tile, in CRS units

  • resolution (Tuple[float, float]) – (Y, X) size of each data point in the grid, in CRS units. Y will usually be negative.

  • origin (Optional[Tuple[float, float]]) – (Y, X) coordinates of a corner of the (0,0) tile in CRS units. default is (0.0, 0.0)

Methods

__init__(crs, tile_size, resolution[, origin])

Create a GridSpec.

grid_range(lower, upper, step)

Return the indices along a 1D scale.

tile_coords(tile_index)

Return Coordinate of the top-left corner of the tile in (Y,X) order.

tile_geobox(tile_index)

Return Tile geobox.

tiles(bounds[, geobox_cache])

Return an iterator of tile_index, GeoBox tuples overlapping bounds.

tiles_from_geopolygon(geopolygon[, …])

Return an iterator of (tile_index, GeoBox) overlapping geopolygon.

Attributes

alignment

Return pixel boundary alignment.

dimensions

List dimension names of the grid spec.

tile_resolution

Calculate tile size in pixels in CRS dimension order (Usually y,x or lat,lon).

Attributes:

alignment

Return pixel boundary alignment.

dimensions

List dimension names of the grid spec.

tile_resolution

Calculate tile size in pixels in CRS dimension order (Usually y,x or lat,lon).

Methods:

grid_range(lower, upper, step)

Return the indices along a 1D scale.

tile_coords(tile_index)

Return Coordinate of the top-left corner of the tile in (Y,X) order.

tile_geobox(tile_index)

Return Tile geobox.

tiles(bounds[, geobox_cache])

Return an iterator of tile_index, GeoBox tuples overlapping bounds.

tiles_from_geopolygon(geopolygon[, …])

Return an iterator of (tile_index, GeoBox) overlapping geopolygon.

property alignment: Tuple[float, float]

Return pixel boundary alignment.

Return type

Tuple[float, float]

property dimensions: Tuple[str, str]

List dimension names of the grid spec.

Return type

Tuple[str, str]

static grid_range(lower, upper, step)[source]

Return the indices along a 1D scale.

Used for producing 2D grid indices.

>>> list(GridSpec.grid_range(-4.0, -1.0, 3.0))
[-2, -1]
>>> list(GridSpec.grid_range(1.0, 4.0, -3.0))
[-2, -1]
>>> list(GridSpec.grid_range(-3.0, 0.0, 3.0))
[-1]
>>> list(GridSpec.grid_range(-2.0, 1.0, 3.0))
[-1, 0]
>>> list(GridSpec.grid_range(-1.0, 2.0, 3.0))
[-1, 0]
>>> list(GridSpec.grid_range(0.0, 3.0, 3.0))
[0]
>>> list(GridSpec.grid_range(1.0, 4.0, 3.0))
[0, 1]
Return type

range

Returns

range of the grid

tile_coords(tile_index)[source]

Return Coordinate of the top-left corner of the tile in (Y,X) order.

Parameters

tile_index (Tuple[int, int]) – in X,Y order

Return type

Tuple[float, float]

tile_geobox(tile_index)[source]

Return Tile geobox.

Parameters

tile_index ((int,int)) –

Return type

GeoBox

property tile_resolution: Tuple[int, int]

Calculate tile size in pixels in CRS dimension order (Usually y,x or lat,lon).

Return type

Tuple[int, int]

tiles(bounds, geobox_cache=None)[source]

Return an iterator of tile_index, GeoBox tuples overlapping bounds.

Tiles come from within the grid, and overlapping with the specified bounds rectangle.

Note

Grid cells are referenced by coordinates (x, y), which is the opposite to the usual CRS dimension order.

Parameters
  • bounds (BoundingBox) – Boundary coordinates of the required grid

  • geobox_cache (dict) – Optional cache to re-use geoboxes instead of creating new one each time

Return type

Iterator[Tuple[Tuple[int, int], GeoBox]]

Returns

iterator of grid cells with GeoBox tiles

tiles_from_geopolygon(geopolygon, tile_buffer=None, geobox_cache=None)[source]

Return an iterator of (tile_index, GeoBox) overlapping geopolygon.

Across the grid and overlapping with the specified geopolygon.

Note

Grid cells are referenced by coordinates (x, y), which is the opposite to the usual CRS dimension order.

Parameters
  • geopolygon (geometry.Geometry) – Polygon to tile

  • tile_buffer (Optional[Tuple[float, float]]) – Optional <float,float> tuple, (extra padding for the query in native units of this GridSpec)

  • geobox_cache (dict) – Optional cache to re-use geoboxes instead of creating new one each time

Return type

Iterator[Tuple[Tuple[int, int], GeoBox]]

Returns

iterator of grid cells with GeoBox tiles