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))]
Parameters
  • crs (geometry.CRS) – Coordinate System used to define the grid

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

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

  • origin ([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]#

Methods

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

grid_range(lower, upper, step)

Returns the indices along a 1D scale.

tile_coords(tile_index)

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

tile_geobox(tile_index)

Tile geobox.

tiles(bounds[, geobox_cache])

Returns an iterator of tile_index, GeoBox tuples across the grid and overlapping with the specified bounds rectangle.

tiles_from_geopolygon(geopolygon[, ...])

Returns an iterator of tile_index, GeoBox tuples across the grid and overlapping with the specified geopolygon.

Attributes

alignment

Pixel boundary alignment

dimensions

List of dimension names of the grid spec

tile_resolution

Tile size in pixels in CRS dimension order (Usually y,x or lat,lon)

Attributes:

alignment

Pixel boundary alignment

dimensions

List of dimension names of the grid spec

tile_resolution

Tile size in pixels in CRS dimension order (Usually y,x or lat,lon)

Methods:

grid_range(lower, upper, step)

Returns the indices along a 1D scale.

tile_coords(tile_index)

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

tile_geobox(tile_index)

Tile geobox.

tiles(bounds[, geobox_cache])

Returns an iterator of tile_index, GeoBox tuples across the grid and overlapping with the specified bounds rectangle.

tiles_from_geopolygon(geopolygon[, ...])

Returns an iterator of tile_index, GeoBox tuples across the grid and overlapping with the specified geopolygon.

property alignment: Tuple[float, float]#

Pixel boundary alignment

Return type

Tuple[float, float]

property dimensions: Tuple[str, str]#

List of dimension names of the grid spec

Return type

Tuple[str, str]

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

Returns 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

tile_coords(tile_index)[source]#

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]#

Tile geobox.

Parameters

tile_index ((int,int)) –

Return type

GeoBox

property tile_resolution: Tuple[int, int]#

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]#

Returns an iterator of tile_index, GeoBox tuples across 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]#

Returns an iterator of tile_index, GeoBox tuples 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