Skip to main content
Glama

tile_raster

Split large raster files into smaller square tiles of a specified size for easier processing and storage. Save tiles individually in a designated directory for efficient geospatial analysis 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
destination_dirYes
sourceYes
tile_sizeYes

Implementation Reference

  • The primary handler for the 'tile_raster' tool. It splits an input raster into square tiles of specified size using rasterio windows and saves each tile as a separate GeoTIFF file.
    @gis_mcp.tool() 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}")
  • Registration/discovery endpoint listing 'tile_raster' among available rasterio operations via the MCP resource.
    @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