Skip to main content
Glama

raster_histogram

Analyze pixel value distribution in raster bands by computing histograms. Input a raster path and specify bin count to generate detailed band-wise data analysis for geospatial insights.

Instructions

Compute histogram of pixel values for each band. Parameters: - source: path to input raster. - bins: number of histogram bins.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
binsNo
sourceYes

Implementation Reference

  • The handler function decorated with @gis_mcp.tool() that implements the raster_histogram tool. It computes the histogram of pixel values for each band in the input raster file using NumPy, handling NoData values with masked arrays.
    @gis_mcp.tool() def raster_histogram( source: str, bins: int = 256 ) -> Dict[str, Any]: """ Compute histogram of pixel values for each band. Parameters: - source: path to input raster. - bins: number of histogram bins. """ try: import rasterio import numpy as np import os src_path = os.path.expanduser(source.replace("`", "")) histograms = {} with rasterio.open(src_path) as src: for i in range(1, src.count + 1): band = src.read(i, masked=True) hist, bin_edges = np.histogram(band.compressed(), bins=bins) histograms[f"Band {i}"] = { "histogram": hist.tolist(), "bin_edges": bin_edges.tolist() } return { "status": "success", "histograms": histograms, "message": f"Histogram computed for all bands." } except Exception as e: raise ValueError(f"Failed to compute histogram: {e}")
  • The MCP resource that lists all available rasterio operations, including 'raster_histogram', allowing discovery of the tool.
    @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" ] }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mahdin75/gis-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server