Skip to main content
Glama

extract_band

Extract a specific band from a multi-band raster and save it as a single-band GeoTIFF. Define input raster, band index, and output path for precise band isolation.

Instructions

Extract a specific band from a multi-band raster and save it as a single-band GeoTIFF. Parameters: - source: path or URL of the input raster. - band_index: index of the band to extract (1-based). - destination: path to save the extracted band raster.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
band_indexYes
destinationYes
sourceYes

Implementation Reference

  • The main handler function for the 'extract_band' tool, decorated with @gis_mcp.tool(). It extracts a specified band from a raster file and saves it as a new single-band GeoTIFF.
    @gis_mcp.tool() def extract_band( source: str, band_index: int, destination: str ) -> Dict[str, Any]: """ Extract a specific band from a multi-band raster and save it as a single-band GeoTIFF. Parameters: - source: path or URL of the input raster. - band_index: index of the band to extract (1-based). - destination: path to save the extracted band raster. """ try: import rasterio src_path = os.path.expanduser(source.replace("`", "")) dst_path = os.path.expanduser(destination.replace("`", "")) with rasterio.open(src_path) as src: if band_index < 1 or band_index > src.count: raise ValueError(f"Band index {band_index} is out of range. This raster has {src.count} bands.") band = src.read(band_index) profile = src.profile.copy() profile.update({ "count": 1 }) os.makedirs(os.path.dirname(dst_path) or ".", exist_ok=True) with rasterio.open(dst_path, "w", **profile) as dst: dst.write(band, 1) return { "status": "success", "destination": str(dst_path), "message": f"Band {band_index} extracted and saved to '{dst_path}'." } except Exception as e: raise ValueError(f"Failed to extract band: {e}")
  • Resource listing 'extract_band' among available rasterio operations, likely used for tool discovery in MCP.
    @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" ] }

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