girs.rastfeat.zonal.zonal_stats¶
-
zonal_stats
(layers, input_raster, field_name, stats, **kwargs)¶ Return a dictionary with zonal statistics
The method:
- collects layer geometries sharing the same value of field_name
- gor each geometry, calculate raster statistics for all pixels coinciding with the geometry
- returns a dictionary with layer’s field values as keys and a dictionary as value
- The dictionary has the raster band as key and a list of statistics as values
- Example of a result (stats=[‘min’, ‘max’] for layer values 10 and 20 and a two bands raster:
- result = {10: {1:[1.92, 67.34], 2:[3.47, 12.87]}, 20: {1:[2.33, 79.41], 2:[4.17, 13.55]}}
Parameters: - layers (LayersSet, filename of a LayersSet, or an ogr-layer) – layer
- input_raster (Raster, filename of a Raster) – raster
- field_name (str) – the layer’s field name. The burn value will be different for each field value
- stats (str, list) – ‘min’, ‘max’, ‘mean’, ‘sum’, ‘count’, or ‘std’
- kwargs –
key layer_number: (int) layer number, default is zero key all_touched: True/False, default all_touched=False
Returns: dictionary with the record values from field field_name as keys and a list of statistics in the same order as given in stats
Return type: dict