RasterSource#

class RasterSource[source]#

Bases: ABC

A source of raster data.

This should be subclassed when adding a new source of raster data such as a set of files, an API, a TMS URI schema, etc.

Attributes

bbox

Bounding box applied to the source imagery.

crs_transformer

Associated CRSTransformer.

dtype

numpy.dtype of the chips read from this source.

extent

Extent of the RasterSource.

num_channels

Number of channels in the chips read from this source.

shape

Shape of the raster as a (height, width, num_channels) tuple.

__init__(channel_order: Optional[List[int]], num_channels_raw: int, bbox: Box, raster_transformers: List[RasterTransformer] = [])[source]#

Constructor.

Parameters
  • channel_order (Optional[List[int]]) – list of channel indices to use when extracting chip from raw imagery.

  • num_channels_raw (int) – Number of channels in the raw imagery before applying channel_order.

  • bbox (Box) – Extent or a crop of the extent.

  • raster_transformers (List[RasterTransformer]) – RasterTransformers for transforming chips whenever they are retrieved. Defaults to [].

Methods

__init__(channel_order, num_channels_raw, bbox)

Constructor.

get_chip(window[, out_shape])

Return the transformed chip in the window.

get_chip_by_map_window(window_map_coords[, ...])

Same as get_chip(), but input is a window in map coords.

get_raw_chip(window[, out_shape])

Return raw chip without applying channel_order or transforms.

resize(chip[, out_shape])

set_bbox(bbox)

Set self.bbox to the given value.

__getitem__(key: Any) ndarray[source]#
Parameters

key (Any) –

Return type

ndarray

__init__(channel_order: Optional[List[int]], num_channels_raw: int, bbox: Box, raster_transformers: List[RasterTransformer] = [])[source]#

Constructor.

Parameters
  • channel_order (Optional[List[int]]) – list of channel indices to use when extracting chip from raw imagery.

  • num_channels_raw (int) – Number of channels in the raw imagery before applying channel_order.

  • bbox (Box) – Extent or a crop of the extent.

  • raster_transformers (List[RasterTransformer]) – RasterTransformers for transforming chips whenever they are retrieved. Defaults to [].

get_chip(window: Box, out_shape: Optional[Tuple[int, int]] = None) ndarray[source]#

Return the transformed chip in the window.

Get a raw chip, extract subset of channels using channel_order, and then apply transformations.

Parameters
  • window (Box) – The window for which to get the chip.

  • out_shape (Optional[Tuple[int, int]]) – (height, width) to resize the chip to.

Returns

Array of shape (…, height, width, channels).

Return type

np.ndarray

get_chip_by_map_window(window_map_coords: Box, out_shape: Optional[Tuple[int, int]] = None) ndarray[source]#

Same as get_chip(), but input is a window in map coords.

Parameters
Return type

ndarray

get_raw_chip(window: Box, out_shape: Optional[Tuple[int, int]] = None) ndarray[source]#

Return raw chip without applying channel_order or transforms.

Parameters
Returns

Array of shape (…, height, width, channels).

Return type

np.ndarray

resize(chip: ndarray, out_shape: Optional[Tuple[int, int]] = None) ndarray[source]#
Parameters
Return type

ndarray

set_bbox(bbox: Box) None[source]#

Set self.bbox to the given value.

Note

This method is idempotent.

Parameters

bbox (Box) – User-specified bbox in pixel coordinates.

Return type

None

property bbox: Box#

Bounding box applied to the source imagery.

abstract property crs_transformer: CRSTransformer#

Associated CRSTransformer.

abstract property dtype: dtype#

numpy.dtype of the chips read from this source.

property extent: Box#

Extent of the RasterSource.

property num_channels: int#

Number of channels in the chips read from this source.

property shape: Tuple[int, int, int]#

Shape of the raster as a (height, width, num_channels) tuple.