Skip to main content
Glama

reclassify_raster

Reclassify raster values by mapping old values to new values using a dictionary, then save the reclassified raster to a specified output path.

Instructions

Reclassify raster values using a mapping dictionary. Args: raster_path: Path to the input raster. reclass_map: Dictionary mapping old values to new values (e.g., {1: 10, 2: 20}). output_path: Path to save the reclassified raster. Returns: Dictionary with status and message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
raster_pathYes
reclass_mapYes
output_pathYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'reclassify_raster' tool. It reads the input raster, applies the reclassification mapping using numpy, and writes the output raster using rasterio.
    def reclassify_raster(raster_path: str, reclass_map: dict, output_path: str) -> Dict[str, Any]:
        """
        Reclassify raster values using a mapping dictionary.
        Args:
            raster_path: Path to the input raster.
            reclass_map: Dictionary mapping old values to new values (e.g., {1: 10, 2: 20}).
            output_path: Path to save the reclassified raster.
        Returns:
            Dictionary with status and message.
        """
        try:
            import rasterio
            import numpy as np
            with rasterio.open(raster_path) as src:
                data = src.read(1)
                profile = src.profile.copy()
                reclass_data = np.copy(data)
                for old, new in reclass_map.items():
                    reclass_data[data == old] = new
            output_path_resolved = resolve_path(output_path, relative_to_storage=True)
            output_path_resolved.parent.mkdir(parents=True, exist_ok=True)
            with rasterio.open(str(output_path_resolved), "w", **profile) as dst:
                dst.write(reclass_data, 1)
            return {
                "status": "success",
                "message": f"Raster reclassified and saved to '{output_path_resolved}'.", 
                "output_path": str(output_path_resolved)
            }
        except Exception as e:
            logger.error(f"Error in reclassify_raster: {str(e)}")
            return {"status": "error", "message": str(e)}
  • Imports the rasterio_functions module (line 69), which triggers the @gis_mcp.tool() decorators to register the reclassify_raster tool with the MCP server.
    from . import (
        geopandas_functions,
        shapely_functions,
        rasterio_functions,
        pyproj_functions,
        pysal_functions,
    )
  • Resource function listing 'reclassify_raster' among available rasterio operations, aiding tool discovery.
    @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"
            ]
        }
  • Wildcard import of rasterio_functions.py in __init__.py, ensuring tools are registered when the package is imported.
    from .rasterio_functions import *
  • Function signature and docstring define the input schema (raster_path: str, reclass_map: dict, output_path: str) and output format.
    def reclassify_raster(raster_path: str, reclass_map: dict, output_path: str) -> Dict[str, Any]:
        """
        Reclassify raster values using a mapping dictionary.
        Args:
            raster_path: Path to the input raster.
            reclass_map: Dictionary mapping old values to new values (e.g., {1: 10, 2: 20}).
            output_path: Path to save the reclassified raster.
        Returns:
            Dictionary with status and message.
        """
Behavior3/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 discloses the tool's behavior by mentioning it creates an output file ('Path to save the reclassified raster') and returns a status dictionary, indicating a write operation. However, it omits details like whether it overwrites existing files, handles errors, or has performance constraints, which are important for a mutation tool.

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

Conciseness4/5

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

The description is well-structured with a clear purpose statement followed by labeled sections for arguments and returns, making it easy to parse. It avoids redundancy, but the 'Args:' and 'Returns:' labels are slightly verbose; a more integrated format could enhance conciseness without losing clarity.

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 complexity (mutation with 3 parameters, no annotations, and an output schema), the description is moderately complete. It covers the core operation and parameters but lacks details on error handling, file formats, or side effects. The presence of an output schema helps by defining the return structure, but more behavioral context 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?

With 0% schema description coverage, the description compensates by explaining all three parameters: 'raster_path' as the input file, 'reclass_map' as a dictionary mapping old to new values with an example, and 'output_path' as the save location. This adds essential meaning beyond the bare schema, though it could specify formats (e.g., file types for paths).

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 ('Reclassify raster values') and the resource involved ('raster'), distinguishing it from sibling tools like 'reproject_raster' or 'clip_raster_with_shapefile' that perform different raster operations. It uses a precise verb ('Reclassify') and specifies the method ('using a mapping dictionary'), making the purpose unambiguous.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives, such as 'raster_algebra' for other raster manipulations or 'write_raster' for saving outputs. It lacks context about prerequisites (e.g., input raster format) or exclusions, leaving the agent to infer usage from the purpose alone.

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