Skip to main content
Glama

tile_raster

Split raster files into manageable square tiles of specified size for easier processing and storage in GIS workflows.

Instructions

Split a raster into square tiles of a given size and save them individually.

Parameters:

  • source: input raster path.

  • tile_size: size of each tile (e.g., 256 or 512).

  • destination_dir: directory to store the tiles.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceYes
tile_sizeYes
destination_dirYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for the 'tile_raster' tool. It reads the source raster, generates square tiles using rasterio.windows.Window, updates the transform and profile for each tile, and writes them as individual GeoTIFF files named tile_{row}_{col}.tif in the destination directory.
    def tile_raster(
        source: str,
        tile_size: int,
        destination_dir: str
    ) -> Dict[str, Any]:
        """
        Split a raster into square tiles of a given size and save them individually.
    
        Parameters:
        - source:         input raster path.
        - tile_size:      size of each tile (e.g., 256 or 512).
        - destination_dir: directory to store the tiles.
        """
        try:
            import os
            import rasterio
            from rasterio.windows import Window
    
            src_path = os.path.expanduser(source.replace("`", ""))
            dst_dir = os.path.expanduser(destination_dir.replace("`", ""))
            os.makedirs(dst_dir, exist_ok=True)
    
            tile_count = 0
    
            with rasterio.open(src_path) as src:
                profile = src.profile.copy()
                for i in range(0, src.height, tile_size):
                    for j in range(0, src.width, tile_size):
                        window = Window(j, i, tile_size, tile_size)
                        transform = src.window_transform(window)
                        data = src.read(window=window)
    
                        out_profile = profile.copy()
                        out_profile.update({
                            "height": data.shape[1],
                            "width": data.shape[2],
                            "transform": transform
                        })
    
                        tile_path = os.path.join(dst_dir, f"tile_{i}_{j}.tif")
                        with rasterio.open(tile_path, "w", **out_profile) as dst:
                            dst.write(data)
    
                        tile_count += 1
    
            return {
                "status": "success",
                "tiles_created": tile_count,
                "message": f"{tile_count} tiles created and saved in '{dst_dir}'."
            }
    
        except Exception as e:
            raise ValueError(f"Failed to tile raster: {e}")
  • Resource function listing 'tile_raster' among available rasterio operations, indicating its registration in the MCP toolset.
    @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"
            ]
        }
  • Import of rasterio_functions module in main.py, which triggers the @gis_mcp.tool() decorators to register the 'tile_raster' tool with the FastMCP server.
    from . import (
        geopandas_functions,
        shapely_functions,
        rasterio_functions,
        pyproj_functions,
        pysal_functions,
    )
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 tool splits and saves tiles, implying a write operation, but lacks details on permissions, whether source files are modified, error handling, or output naming conventions. This is a significant gap for a tool with potential side effects.

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 appropriately sized and front-loaded, with a clear purpose statement followed by parameter details. Every sentence adds value, though the parameter list could be integrated more seamlessly. It avoids redundancy and is easy to scan.

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 (3 parameters, no annotations, but with an output schema), the description is partially complete. It covers the basic operation and parameters but lacks behavioral details like side effects or error conditions. The output schema likely handles return values, so the description's focus on inputs is acceptable.

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 adds meaningful context for all three parameters: 'source' as an input raster path, 'tile_size' with examples (256 or 512), and 'destination_dir' for storage. This clarifies semantics beyond the bare schema, though it could specify units for tile_size or path formats.

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 tool's purpose with specific verbs ('split', 'save') and resources ('raster', 'square tiles'), and distinguishes it from sibling tools like 'clip_raster_with_shapefile' or 'reproject_raster' by focusing on tiling operations. It avoids tautology by not merely repeating the name 'tile_raster'.

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. It does not mention prerequisites, such as input raster format requirements, or compare it to similar tools like 'clip_raster_with_shapefile' for spatial subsetting. Usage is implied only by the tool's name and description.

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