Skip to main content
Glama

extract_band

Extract a specific band from a multi-band raster and save it as a single-band GeoTIFF for focused geospatial analysis.

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
sourceYes
band_indexYes
destinationYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'extract_band' tool. It reads a specific band from the source raster using rasterio, copies the profile, updates the band count to 1, and writes the extracted band to the destination path.
    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}")
  • The 'extract_band' tool is registered/listed in the rasterio operations resource, which provides a list of available rasterio tools.
    @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"
            ]
        }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions the action ('extract and save') but lacks details on permissions needed, whether the source raster is modified, error handling (e.g., invalid band index), or performance aspects like file size limits. The description is minimal and does not compensate for the absence of annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose in the first sentence, followed by a structured parameter list. Each sentence earns its place by defining the tool's function and clarifying parameters without redundancy. It is appropriately sized for a tool with three parameters.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (raster processing), no annotations, and an output schema (which handles return values), the description is adequate but incomplete. It covers the purpose and parameters but lacks behavioral context (e.g., side effects, error cases). The presence of an output schema reduces the need to explain returns, but more operational details would improve completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It clearly explains each parameter: 'source' as the input raster path/URL, 'band_index' as the 1-based index to extract, and 'destination' as the output path. This adds meaningful context beyond the bare schema types, though it could specify format details (e.g., supported URL schemes).

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('extract a specific band from a multi-band raster'), the resource ('raster'), and the outcome ('save it as a single-band GeoTIFF'). It distinguishes itself from sibling tools like 'concat_bands' (which combines bands) and 'raster_band_statistics' (which analyzes bands) by focusing on extraction and saving.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when needing to isolate a single band from a multi-band raster for GeoTIFF output, but it does not explicitly state when to use this tool versus alternatives like 'raster_band_statistics' for analysis or 'write_raster' for general raster saving. No exclusions or prerequisites are mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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