raster_band_statistics
Calculate minimum, maximum, mean, and standard deviation for each band of a raster. Analyze spatial data efficiently by processing raster input from local or URL sources.
Instructions
Calculate min, max, mean, and std for each band of a raster.
Parameters:
- source: path to input raster (local or URL).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| source | Yes |
Implementation Reference
- The handler function decorated with @gis_mcp.tool() that calculates min, max, mean, and std deviation for each band in the raster file, handling NoData values with masked arrays.@gis_mcp.tool() def raster_band_statistics( source: str ) -> Dict[str, Any]: """ Calculate min, max, mean, and std for each band of a raster. Parameters: - source: path to input raster (local or URL). """ try: import numpy as np import rasterio src_path = os.path.expanduser(source.replace("`", "")) stats = {} with rasterio.open(src_path) as src: for i in range(1, src.count + 1): band = src.read(i, masked=True) # masked array handles NoData stats[f"Band {i}"] = { "min": float(band.min()), "max": float(band.max()), "mean": float(band.mean()), "std": float(band.std()) } return { "status": "success", "statistics": stats, "message": f"Band-wise statistics computed successfully." } except Exception as e: raise ValueError(f"Failed to compute statistics: {e}")
- src/gis_mcp/rasterio_functions.py:11-35 (registration)The resource endpoint that lists all available rasterio tools/operations, including 'raster_band_statistics', for discovery in the MCP system.@gis_mcp.resource("gis://operation/rasterio") def get_rasterio_operations() -> Dict[str, List[str]]: """List available rasterio operations.""" return { "operations": [ "metadata_raster", "get_raster_crs", "clip_raster_with_shapefile", "resample_raster", "reproject_raster", "weighted_band_sum", "concat_bands", "raster_algebra", "compute_ndvi", "raster_histogram", "tile_raster", "raster_band_statistics", "extract_band", "zonal_statistics", "reclassify_raster", "focal_statistics", "hillshade", "write_raster" ] }