RasterizedSource#

class RasterizedSource[source]#

Bases: RasterSource

A RasterSource based on the rasterization of a VectorSource.

Attributes

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, extent: Box, 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.

  • extent (Box) – Extent of corresponding imagery RasterSource.

  • all_touched (bool, optional) – 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)

Return the transformed chip in the window.

get_image_array()

Return entire transformed image array.

get_raw_chip(window)

Return raw chip without applying channel_order or transforms.

get_raw_image_array()

Return raw image for the full extent.

validate_labels(df)

Validate label geometries.

__init__(vector_source: VectorSource, background_class_id: int, extent: Box, 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.

  • extent (Box) – Extent of corresponding imagery RasterSource.

  • all_touched (bool, optional) – 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) np.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.

Returns

Array of shape (height, width, channels).

Return type

np.ndarray

get_image_array() np.ndarray#

Return entire transformed image array.

Warning

Not safe to call on very large RasterSources.

Returns

Array of shape (height, width, channels).

Return type

np.ndarray

get_raw_chip(window: Box) np.ndarray#

Return raw chip without applying channel_order or transforms.

Parameters

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

Returns

Array of shape (height, width, channels).

Return type

np.ndarray

get_raw_image_array() np.ndarray#

Return raw image for the full extent.

Warning

Not safe to call on very large RasterSources.

Returns

Array of shape (height, width, channels).

Return type

np.ndarray

validate_labels(df: geopandas.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 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.