Skip to main content
Glama

get_raster_crs

Retrieve the Coordinate Reference System (CRS) of a raster dataset to understand its geospatial reference for accurate GIS analysis and transformations.

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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'get_raster_crs' tool. It opens a raster file (local or URL), extracts its CRS using rasterio, and returns it in PROJ.4 dictionary and WKT formats.
    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}")
  • Helper resource that lists 'get_raster_crs' among available rasterio operations, aiding in 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"
            ]
        }
  • src/gis_mcp/mcp.py:1-6 (registration)
    Definition of the FastMCP instance 'gis_mcp' used to register all tools via decorators.
    # MCP imports using the new SDK patterns
    from fastmcp import FastMCP
    
    
    gis_mcp = FastMCP("GIS MCP")
  • Import of rasterio_functions module in main.py, which triggers registration of the get_raster_crs tool via its @gis_mcp.tool() decorator.
    from . import (
        geopandas_functions,
        shapely_functions,
        rasterio_functions,
        pyproj_functions,
        pysal_functions,
    )
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden and does well by disclosing key behaviors: it opens the raster file/URL, reads the DatasetReader.crs attribute, and returns both PROJ.4-style dict and WKT representation. It doesn't mention error handling, performance characteristics, or authentication needs, but provides solid operational transparency.

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

Conciseness5/5

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

Three well-structured sentences with zero waste: first states purpose, second explains the operation, third specifies return values. Every sentence earns its place by adding distinct information. The description is appropriately sized and front-loaded with the core purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a single-parameter read operation with an output schema (which handles return value documentation), the description provides good completeness. It covers purpose, input semantics, and operational behavior. The main gap is lack of explicit usage guidelines versus sibling tools, but otherwise addresses what's needed beyond structured fields.

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 for the single parameter 'path_or_url', the description compensates by explaining what this parameter represents ('local path or HTTPS URL') and how it's used ('Opens the raster'). This adds meaningful context beyond the bare schema, though it doesn't specify format requirements or constraints.

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 ('Retrieve'), resource ('Coordinate Reference System of a raster dataset'), and scope (PROJ.4-style dict and WKT representation). It distinguishes itself from sibling tools like 'get_crs_info' or 'get_geocentric_crs' by focusing specifically on raster datasets rather than general CRS operations.

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

Usage Guidelines3/5

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

The description implies usage context by specifying it works with 'raster dataset' and accepts 'local path or HTTPS URL', but doesn't explicitly state when to use this tool versus alternatives like 'get_crs_info' or 'get_geocentric_crs'. No explicit exclusions or prerequisites are mentioned.

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