reVX.exclusions.base.Rasterizer

class Rasterizer(shape, profile, weights_calculation_upscale_factor=None)[source]

Bases: object

Helper class to rasterize shapes.

Parameters:
  • shape (tuple) – Shape of the output (i.e. exclusion) array. Should contain a band dimension as the first dimension.

  • profile (dict) – Geotiff profile containing the transform and CRS information necessary for rasterization.

  • weights_calculation_upscale_factor (int, optional) – If this value is an int > 1, the output will be a layer with inclusion weight values (floats ranging from 0 to 1). Note that this is backwards w.r.t the typical output of exclusion integer values (1 for excluded, 0 otherwise). Values <= 1 will still return a standard exclusion mask. For example, a cell that was previously excluded with a a boolean mask (value of 1) may instead be converted to an inclusion weight value of 0.75, meaning that 75% of the area corresponding to that point should be included (i.e. the exclusion feature only intersected a small portion - 25% - of the cell). This percentage inclusion value is calculated by upscaling the output array using this input value, rasterizing the exclusion features onto it, and counting the number of resulting sub-cells excluded by the feature. For example, setting the value to 3 would split each output cell into nine sub-cells - 3 divisions in each dimension. After the feature is rasterized on this high-resolution sub-grid, the area of the non-excluded sub-cells is totaled and divided by the area of the original cell to obtain the final inclusion percentage. Therefore, a larger upscale factor results in more accurate percentage values. If None (or a value <= 1), this process is skipped and the output is a boolean exclusion mask. By default None.

Methods

rasterize(shapes[, window])

Convert geometries into exclusions array.

rasterize_within_window(features, bounds)

Rasterize the features using the GeoSeries bounding box

Attributes

arr_shape

Rasterize array shape.

inclusions

Flag indicating whether or not the output raster represents inclusion values.

profile

Geotiff profile.

scale_factor

Integer upscale factor used to calculate inclusion weights

transform

Affine transform for exclusion layer.

property scale_factor

Integer upscale factor used to calculate inclusion weights

property profile

Geotiff profile.

Returns:

dict

property transform

Affine transform for exclusion layer.

Type:

rasterio.Affine

property arr_shape

Rasterize array shape.

Returns:

tuple

property inclusions

Flag indicating whether or not the output raster represents inclusion values.

Returns:

bool

rasterize(shapes, window=None)[source]

Convert geometries into exclusions array.

Parameters:
  • shapes (list, optional) – List of geometries to rasterize (i.e. list(gdf[“geometry”])). If None or empty list, returns array of zeros.

  • window (rasterio.windows.Window) – A rasterio window defining the area of the raster. Can be used to speed up computation and decrease memory requirements if features are localized to a small portion of the raster array.

Returns:

arr (ndarray) – Rasterized array of shapes.

rasterize_within_window(features, bounds)[source]

Rasterize the features using the GeoSeries bounding box

Parameters:
  • features (list) – List of geometries to rasterize (i.e. list(gdf[“geometry”])).

  • bounds (tuple) – Bounding box to rasterize within, in the form (left, bottom, right, top).

Returns:

  • arr (ndarray) – Rasterized array of shapes within the bounding box.

  • slices (2-tuple of slice) – X and Y slice objects defining where in the original array the exclusion data should go.