exactextract.exact_extract

Functions

exact_extract(rast, vec, ops, *[, weights, ...])

Calculate zonal statistics.

Module Contents

exactextract.exact_extract.exact_extract(rast, vec, ops, *, weights=None, include_cols=None, include_geom=False, strategy: str = 'feature-sequential', max_cells_in_memory: int = 30000000, grid_compat_tol: float = 0.001, output: str = 'geojson', output_options: Mapping | None = None, progress=False)[source]

Calculate zonal statistics.

Parameters:
  • rast – One or a list of RasterSource object(s) or filename(s) that can be opened by GDAL/rasterio/xarray.

  • vec – A FeatureSource or filename that can be opened by GDAL/fiona

  • ops – A list of Operation objects, or strings that can be used to construct them (e.g., "mean", "quantile(q=0.33)"). Check out Available operations for more information.

  • weights – An optional RasterSource or filename for weights to be used in weighted operations.

  • include_cols – An optional list of columns from the input features to be included into the output.

  • include_geom – Flag indicating whether the geometry should be copied from the input features into the output.

  • strategy

    Specifies the strategy to use when processing features. Detailed performance notes are available in Performance - Processing strategies. Must be set to one of:

    • "feature-sequential" (the default): iterate over the features in vec, read the corresponding pixels from rast/weights, and compute the summary operations. This offers predictable memory consumption but may be inefficient if the order of features in vec causes the same, relatively large raster blocks to be read and decompressed many times.

    • "raster-sequential": iterate over chunks of pixels in rast, identify the intersecting features from vec, and compute statistics. This performs better than strategy="feature-sequential" in some cases, but comes at a cost of higher memory usage.

  • max_cells_in_memory – Indicates the maximum number of raster cells that should be loaded into memory at a given time.

  • grid_compat_tol – require value and weight grids to align within grid_compat_tol times the smaller of the two grid resolutions

  • output

    An OutputWriter or one of the following strings:

    • ”geojson” (the default): return a list of GeoJSON-like features

    • ”pandas”: return a pandas.DataFrame or geopandas.GeoDataFrame,

      depending on the value of include_geom

    • ”gdal”: write results to disk using GDAL/OGR as they are written. This

      option (with strategy="feature-sequential") avoids the need to maintain results for all features in memory at a single time, which may be significant for operations with large result sizes such as cell_id, values, etc.

  • output_options – an optional dictionary of options passed to the writer.JSONWriter, writer.PandasWriter, or writer.GDALWriter.

  • progress – if True, a progress bar will be displayed. Alternatively, a function may be provided that will be called with the completion fraction and a status message.