rasterize#

geodesic.boson.rasterize(attribute_name=None, value=None, use_z=False, initialize_value=None, invert=False, all_touched=False, add=False, input_collection=None, asset_name='rasterized', band_name='rasterized', feature_limit=25000)[source]#

Creates a rasterized image from a feature collection as a new raster asset.

Rasterize middleware is useful for performing simple aggregations on a feature collection. This can be useful for things like creating a population density raster from a feature collection of population counts or creating a binary raster from a feature collection of labels in a segmentation task.

Parameters:
  • attribute_name (str | None) – attribute name to rasterize. Defaults to None.

  • value (Any | None) – value to rasterize. Defaults to None.

  • use_z (bool) – whether to use the z value of the feature. Defaults to False.

  • initialize_value (Any | None) – value to initialize the raster with. Defaults to None.

  • invert (bool) – invert which pixels are rasterize. Defaults to False.

  • all_touched (bool) – whether to rasterize all pixels touched by the feature. Defaults to False.

  • add (bool) – whether to add the raster to the asset. Defaults to False.

  • input_collection (str | None) – collection to rasterize. Defaults to None (all/default collection).

  • asset_name (str) – name of the asset to create. Defaults to “rasterized”.

  • band_name (str) – name of the band to create. Defaults to “rasterized”.

  • feature_limit (int) – maximum number of features to rasterize. Defaults to 25000.

Examples

>>> # Rasterize the population attribute by summing the values in the attribute for each pixel
>>> transform = rasterize(
... attribute_name="population",
... add=True,
... asset_name="population_raster",
... band_name="population"
... )
>>> # Rasterize by object by setting the value to 1 wherever there is an object
>>> transform = rasterize(
... value=1
... )
>>> # Rasterize by object by setting the value to 1 wherever there is NOT an object
>>> transform = rasterize(
... value=1,
... invert=True
... )