Skip to main content
Glama

get_raster_crs

Retrieve the Coordinate Reference System (CRS) of a raster dataset, returning both PROJ.4-style dict and WKT formats. Use with local paths or HTTPS URLs to identify spatial reference details.

Instructions

Retrieve the Coordinate Reference System (CRS) of a raster dataset. Opens the raster (local path or HTTPS URL), reads its DatasetReader.crs attribute as a PROJ.4-style dict, and also returns the WKT representation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
path_or_urlYes

Implementation Reference

  • The handler function decorated with @gis_mcp.tool() that opens a raster file (local or URL), retrieves its CRS using rasterio, and returns it in PROJ4 dict and WKT formats.
    @gis_mcp.tool() def get_raster_crs(path_or_url: str) -> Dict[str, Any]: """ Retrieve the Coordinate Reference System (CRS) of a raster dataset. Opens the raster (local path or HTTPS URL), reads its DatasetReader.crs attribute as a PROJ.4-style dict, and also returns the WKT representation. """ try: import numpy as np import rasterio # Strip backticks if the client wrapped the input in them cleaned = path_or_url.replace("`", "") # Open remote or local dataset if cleaned.lower().startswith("https://"): src = rasterio.open(cleaned) else: local_path = os.path.expanduser(cleaned) if not os.path.isfile(local_path): raise FileNotFoundError(f"Raster file not found at '{local_path}'.") src = rasterio.open(local_path) # Access the CRS object on the opened dataset crs_obj = src.crs src.close() if crs_obj is None: raise ValueError("No CRS defined for this dataset.") # Convert CRS to PROJ.4‐style dict and WKT string proj4_dict = crs_obj.to_dict() # e.g., {'init': 'epsg:32618'} wkt_str = crs_obj.to_wkt() # full WKT representation return { "status": "success", "proj4": proj4_dict, "wkt": wkt_str, "message": "CRS retrieved successfully" } except Exception as e: # Log and re-raise as ValueError for MCP error propagation logger.error(f"Error retrieving CRS for '{path_or_url}': {e}") raise ValueError(f"Failed to retrieve CRS: {e}")
  • Registers the get_raster_crs tool as part of the available rasterio operations list via the @gis_mcp.resource decorator for 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" ] }

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