reVX.setbacks.base.Rasterizer

class Rasterizer(excl_fpath, weights_calculation_upscale_factor, hsds=False)[source]

Bases: object

Helper class to rasterize shapes.

Parameters:
  • excl_fpath (str) – Path to .h5 file containing template layers. The raster will match the shape and profile of these layers.

  • weights_calculation_upscale_factor (int) – 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.

Attributes

arr_shape

Rasterize array shape.

inclusions

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

profile

Geotiff profile.

transform

Affine transform for exclusion layer.

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 wether 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.