Skip to main content
Glama

overlay_gpd

Perform spatial overlay analysis on two geospatial files using intersection, union, identity, symmetric difference, or difference methods. Returns overlay results as a new GeoDataFrame.

Instructions

Overlay two GeoDataFrames using geopandas.overlay. Args: gdf1_path: Path to the first geospatial file. gdf2_path: Path to the second geospatial file. how: Overlay method ('intersection', 'union', 'identity', 'symmetric_difference', 'difference'). output_path: Optional path to save the result. Returns: Dictionary with status, message, and output info.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
gdf1_pathYes
gdf2_pathYes
howNointersection
output_pathNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The `overlay_gpd` function is the core implementation of the overlay_gpd tool. It reads two GeoDataFrames from file paths, optionally reprojects to match CRS, performs a spatial overlay using geopandas.overlay() with configurable 'how' (intersection, union, identity, symmetric_difference, difference), optionally saves the result, and returns status, feature count, CRS, columns, and a WKT-based preview.
    def overlay_gpd(gdf1_path: str, gdf2_path: str, how: str = "intersection", output_path: str = None) -> Dict[str, Any]:
        """
        Overlay two GeoDataFrames using geopandas.overlay.
        Args:
            gdf1_path: Path to the first geospatial file.
            gdf2_path: Path to the second geospatial file.
            how: Overlay method ('intersection', 'union', 'identity', 'symmetric_difference', 'difference').
            output_path: Optional path to save the result.
        Returns:
            Dictionary with status, message, and output info.
        """
        try:
            gdf1 = gpd.read_file(gdf1_path)
            gdf2 = gpd.read_file(gdf2_path)
            if gdf1.crs != gdf2.crs:
                gdf2 = gdf2.to_crs(gdf1.crs)
            result = gpd.overlay(gdf1, gdf2, how=how)
            if output_path:
                output_path_resolved = resolve_path(output_path, relative_to_storage=True)
                output_path_resolved.parent.mkdir(parents=True, exist_ok=True)
                result.to_file(str(output_path_resolved))
                output_path = str(output_path_resolved)
            # Convert geometry to WKT for serialization
            preview_df = result.head(5).copy()
            if 'geometry' in preview_df.columns:
                preview_df['geometry'] = preview_df['geometry'].apply(lambda g: g.wkt if g is not None else None)
            preview = preview_df.to_dict(orient="records")
            return {
                "status": "success",
                "message": f"Overlay ({how}) completed successfully.",
                "num_features": len(result),
                "crs": str(result.crs),
                "columns": list(result.columns),
                "preview": preview,
                "output_path": output_path,
            }
        except Exception as e:
            logger.error(f"Error in overlay_gpd: {str(e)}")
            return {"status": "error", "message": str(e)}
  • The `@gis_mcp.tool()` decorator on line 183 registers `overlay_gpd` as an MCP tool. The `gis_mcp` instance is a FastMCP object from fastmcp, created in mcp.py.
    @gis_mcp.tool()
    def overlay_gpd(gdf1_path: str, gdf2_path: str, how: str = "intersection", output_path: str = None) -> Dict[str, Any]:
  • The resource listing at 'gis://geopandas/io' includes 'overlay_gpd' as an available operation, providing discovery for clients.
    @gis_mcp.resource("gis://geopandas/io")
    def get_geopandas_io() -> Dict[str, List[str]]:
        """List available GeoPandas I/O operations."""
        return {
            "operations": [
                "read_file_gpd",
                "to_file_gpd",
                "overlay_gpd",
                "dissolve_gpd",
                "explode_gpd",
                "clip_vector",
                "write_file_gpd"
            ]
        }
  • The `resolve_path` helper function is used by overlay_gpd to resolve output paths relative to the storage directory when saving result files.
    def resolve_path(file_path: str, relative_to_storage: bool = True) -> Path:
        """
        Resolve a file path, optionally making it relative to the storage directory.
        
        If the path is absolute, it's used as-is. If relative and relative_to_storage
        is True, it's resolved relative to the storage directory.
        
        Args:
            file_path: The file path to resolve
            relative_to_storage: If True and path is relative, resolve relative to storage
            
        Returns:
            Resolved Path object
        """
        path = Path(file_path)
        
        # If absolute path, use as-is
        if path.is_absolute():
            return path.expanduser().resolve()
  • The function signature defines the input schema for the overlay_gpd tool: gdf1_path (str), gdf2_path (str), how (str, default 'intersection'), output_path (str, optional). The return type is Dict[str, Any] with status, message, num_features, crs, columns, preview, output_path.
    def overlay_gpd(gdf1_path: str, gdf2_path: str, how: str = "intersection", output_path: str = None) -> Dict[str, Any]:
        """
        Overlay two GeoDataFrames using geopandas.overlay.
        Args:
            gdf1_path: Path to the first geospatial file.
            gdf2_path: Path to the second geospatial file.
            how: Overlay method ('intersection', 'union', 'identity', 'symmetric_difference', 'difference').
            output_path: Optional path to save the result.
        Returns:
            Dictionary with status, message, and output info.
        """
        try:
            gdf1 = gpd.read_file(gdf1_path)
            gdf2 = gpd.read_file(gdf2_path)
            if gdf1.crs != gdf2.crs:
                gdf2 = gdf2.to_crs(gdf1.crs)
            result = gpd.overlay(gdf1, gdf2, how=how)
            if output_path:
                output_path_resolved = resolve_path(output_path, relative_to_storage=True)
                output_path_resolved.parent.mkdir(parents=True, exist_ok=True)
                result.to_file(str(output_path_resolved))
                output_path = str(output_path_resolved)
            # Convert geometry to WKT for serialization
            preview_df = result.head(5).copy()
            if 'geometry' in preview_df.columns:
                preview_df['geometry'] = preview_df['geometry'].apply(lambda g: g.wkt if g is not None else None)
            preview = preview_df.to_dict(orient="records")
            return {
                "status": "success",
                "message": f"Overlay ({how}) completed successfully.",
                "num_features": len(result),
                "crs": str(result.crs),
                "columns": list(result.columns),
                "preview": preview,
                "output_path": output_path,
            }
        except Exception as e:
            logger.error(f"Error in overlay_gpd: {str(e)}")
            return {"status": "error", "message": str(e)}
Behavior3/5

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

No annotations are provided, so the description carries full burden. It states it uses geopandas.overlay and returns a dict with status, message, and output info, but lacks details on error handling, side effects, or prerequisites (e.g., file existence, CRS matching).

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 concise and well-structured with a docstring format (Args, Returns). It front-loads the main purpose and provides necessary details without extraneous text.

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 complexity (4 params, output schema exists), the description covers param descriptions and return structure. However, it could be more complete by mentioning file format expectations and CRS handling, and referencing siblings.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, so description must add meaning. It explains each parameter's purpose and lists valid options for 'how', but does not specify expected file formats or path requirements.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'overlay' and resource 'GeoDataFrames', and mentions using geopandas.overlay. It distinguishes from siblings by being a generic overlay tool with a 'how' parameter, but could be more explicit about its flexibility.

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?

No guidance on when to use this tool versus alternatives like the specific intersection, union, etc. siblings. The description only explains what it does, not when it's appropriate.

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