RasterizedSource#

class RasterizedSource[source]#

Bases: RasterSource

A RasterSource based on the rasterization of a VectorSource.

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__(vector_source: VectorSource, background_class_id: int, bbox: Box | None = None, all_touched: bool = False, raster_transformers: list['RasterTransformer'] = [])[source]#

Constructor.

Parameters:
  • vector_source (VectorSource) – The VectorSource to rasterize.

  • background_class_id (int) – The class_id to use for any background pixels, ie. pixels not covered by a polygon.

  • bbox (Box | None) – User-specified crop of the extent. If None, the full extent available in the source file is used.

  • all_touched (bool) – If True, all pixels touched by geometries will be burned in. If false, only pixels whose center is within the polygon or that are selected by Bresenham’s line algorithm will be burned in. (See rasterize() for more details). Defaults to False.

  • raster_transformers (list['RasterTransformer']) –

Methods

__init__(vector_source, background_class_id)

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.

validate_labels(df)

Validate label geometries.

__getitem__(key: Any) ndarray#
Parameters:

key (Any) –

Return type:

ndarray

__init__(vector_source: VectorSource, background_class_id: int, bbox: Box | None = None, all_touched: bool = False, raster_transformers: list['RasterTransformer'] = [])[source]#

Constructor.

Parameters:
  • vector_source (VectorSource) – The VectorSource to rasterize.

  • background_class_id (int) – The class_id to use for any background pixels, ie. pixels not covered by a polygon.

  • bbox (Box | None) – User-specified crop of the extent. If None, the full extent available in the source file is used.

  • all_touched (bool) – If True, all pixels touched by geometries will be burned in. If false, only pixels whose center is within the polygon or that are selected by Bresenham’s line algorithm will be burned in. (See rasterize() for more details). Defaults to False.

  • raster_transformers (list['RasterTransformer']) –

get_chip(window: Box, out_shape: tuple[int, int] | None = None) ndarray#

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 (tuple[int, int] | None) – (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, *args, **kwargs) ndarray#

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

Parameters:

window_map_coords (Box) –

Return type:

ndarray

get_raw_chip(window: Box, out_shape: tuple[int, int] | None = None) ndarray#

Return raw chip without applying channel_order or transforms.

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

  • out_shape (tuple[int, int] | None) –

Returns:

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

Return type:

np.ndarray

resize(chip: ndarray, out_shape: tuple[int, int] | None = None) ndarray#
Parameters:
Return type:

ndarray

set_bbox(bbox: Box) None#

Set self.bbox to the given value.

Note

This method is idempotent.

Parameters:

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

Return type:

None

validate_labels(df: GeoDataFrame) None[source]#

Validate label geometries.

Parameters:

df (gpd.GeoDataFrame) – Label geometries.

Raises:
  • ValueError – If Point or LineString geometries found.

  • ValueError – If geometries are missing class IDs.

Return type:

None

property bbox: Box#

Bounding box applied to the source imagery.

property crs_transformer#

Associated CRSTransformer.

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.