Skip to main content
Glama

concat_bands

Combine multiple single-band raster files into a single multi-band raster, automatically resolving alignment issues like mismatched CRS, resolution, or dimensions. Input folder_path to specify files and destination for the output.

Instructions

Concatenate multiple single-band raster files into one multi-band raster, handling alignment issues automatically. Parameters: - folder_path: Path to folder containing input raster files (e.g. GeoTIFFs). - destination: Path to output multi-band raster file. Notes: - Files are read in sorted order by filename. - If rasters have mismatched CRS, resolution, or dimensions, they are aligned automatically.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
destinationYes
folder_pathYes

Implementation Reference

  • The core handler function for the 'concat_bands' tool. It concatenates single-band TIFF files from a folder into a multi-band raster, automatically aligning mismatched rasters using reprojection if necessary.
    @gis_mcp.tool() def concat_bands( folder_path: str, destination: str ) -> Dict[str, Any]: """ Concatenate multiple single-band raster files into one multi-band raster, handling alignment issues automatically. Parameters: - folder_path: Path to folder containing input raster files (e.g. GeoTIFFs). - destination: Path to output multi-band raster file. Notes: - Files are read in sorted order by filename. - If rasters have mismatched CRS, resolution, or dimensions, they are aligned automatically. """ try: import rasterio import numpy as np from rasterio.warp import reproject, calculate_default_transform, Resampling from glob import glob folder_path = os.path.expanduser(folder_path.replace("`", "")) dst_path = os.path.expanduser(destination.replace("`", "")) # Collect single-band TIFF files in folder files = sorted(glob(os.path.join(folder_path, "*.tif"))) if len(files) == 0: raise ValueError("No .tif files found in folder.") # Read properties of the first file for reference with rasterio.open(files[0]) as ref: meta = ref.meta.copy() height, width = ref.height, ref.width crs = ref.crs transform = ref.transform dtype = ref.dtypes[0] meta.update(count=len(files), dtype=dtype) os.makedirs(os.path.dirname(dst_path) or ".", exist_ok=True) with rasterio.open(dst_path, "w", **meta) as dst: for idx, fp in enumerate(files, start=1): with rasterio.open(fp) as src: band = src.read(1) # Auto-align raster if size or CRS mismatch occurs if src.height != height or src.width != width or src.crs != crs or src.transform != transform: new_transform, new_width, new_height = calculate_default_transform( src.crs, crs, src.width, src.height, *src.bounds ) aligned_band = np.zeros((new_height, new_width), dtype=dtype) reproject( source=band, destination=aligned_band, src_transform=src.transform, src_crs=src.crs, dst_transform=new_transform, dst_crs=crs, resampling=Resampling.bilinear ) band = aligned_band dst.write(band, idx) return { "status": "success", "destination": str(dst_path), "message": f"{len(files)} single-band rasters concatenated into '{dst_path}'." } except Exception as e: raise ValueError(f"Failed to concatenate rasters: {e}")
  • GIS MCP resource that lists all available rasterio operations, including 'concat_bands', serving as the tool registry/discovery endpoint.
    @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