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 unitsresolution (
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 unitsresolution (
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
Return pixel boundary alignment.
List dimension names of the grid spec.
Calculate tile size in pixels in CRS dimension order (Usually y,x or lat,lon).
Attributes:
Return pixel boundary alignment.
List dimension names of the grid spec.
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.
- property dimensions: Tuple[str, str]¶
List dimension names of the grid spec.
- 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
- Returns
range of the grid
- tile_coords(tile_index)[source]¶
Return Coordinate of the top-left corner of the tile in (Y,X) order.
- property tile_resolution: Tuple[int, int]¶
Calculate tile size in pixels in CRS dimension order (Usually y,x or lat,lon).
- 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.
- 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
- Return type
- Returns
iterator of grid cells with
GeoBox
tiles