remotior_sensus.tools.raster_zonal_stats module

Raster zonal stats.

This tool allows for calculating statistics of a raster intersecting a vector.

Typical usage example:

>>> # import Remotior Sensus and start the session
>>> import remotior_sensus
>>> rs = remotior_sensus.Session()
>>> # start the process
>>> statistics = rs.raster_zonal_stats(
... raster_path='input_path', reference_path='input_vector_path',
... vector_field='field_name', output_path='output_path',
... stat_names=['Sum', 'Mean'])
remotior_sensus.tools.raster_zonal_stats.raster_zonal_stats(raster_path: str, reference_path: str, vector_field: str | None = None, output_path: str | None = None, stat_names: str | list | None = None, stat_percentile: int | str | list | None = None, extent_list: list | None = None, n_processes: None | int = None, available_ram: None | int = None, progress_message: bool | None = True) OutputManager

Raster zonal stats based on a polygon vector field.

This tool allows for calculating statistics of a raster intersecting a vector. For each unique value in the vector field, one ore more statistics can be calculated based on raster pixel values intersecting the vector polygons. The output is a csv file and a numpy records table including the statistics for each unique value in the vector field. Available functions are:

  • Count

  • Max

  • Mean

  • Median

  • Min

  • Percentile

  • StandardDeviation

  • Sum

Parameters:
  • raster_path – path of raster used as input.

  • reference_path – path of the vector or raster file used as reference input.

  • vector_field – the name of the vector field used as reference value.

  • stat_names – statistic name as in configurations.statistics_list.

  • stat_percentile – integer value for percentile parameter.

  • output_path – string of output directory path.

  • extent_list – list of boundary coordinates left top right bottom.

  • n_processes – number of parallel processes.

  • available_ram – number of megabytes of RAM available to processes.

  • progress_message – if True then start progress message, if False does not start the progress message (useful if launched from other tools).

Returns:

object OutputManager() with
  • path = output csv path

  • extra = {‘table’: table as numpy records}

Examples

Perform the calculation
>>> stats = raster_zonal_stats(
... raster_path='input_path', reference_path='input_vector_path',
... vector_field='field_name',output_path='output_path',
... stat_names=['Percentile', 'Max', 'Min'],stat_percentile=[1, 99]
... )