Skip to main content
Glama

sjoin_gpd

Perform spatial joins between geospatial datasets to combine attributes based on geographic relationships like intersection or containment.

Instructions

Spatial join between two GeoDataFrames using geopandas.sjoin. Args: left_path: Path to the left geospatial file. right_path: Path to the right geospatial file. how: Type of join ('left', 'right', 'inner'). predicate: Spatial predicate ('intersects', 'within', 'contains', etc.). output_path: Optional path to save the result. Returns: Dictionary with status, message, and output info.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
left_pathYes
right_pathYes
howNoinner
predicateNointersects
output_pathNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Main handler function for the 'sjoin_gpd' tool, performing spatial join on two GeoDataFrames using geopandas.sjoin.
    @gis_mcp.tool()
    def sjoin_gpd(left_path: str, right_path: str, how: str = "inner", predicate: str = "intersects", output_path: str = None) -> Dict[str, Any]:
        """
        Spatial join between two GeoDataFrames using geopandas.sjoin.
        Args:
            left_path: Path to the left geospatial file.
            right_path: Path to the right geospatial file.
            how: Type of join ('left', 'right', 'inner').
            predicate: Spatial predicate ('intersects', 'within', 'contains', etc.).
            output_path: Optional path to save the result.
        Returns:
            Dictionary with status, message, and output info.
        """
        try:
            left = gpd.read_file(left_path)
            right = gpd.read_file(right_path)
            if left.crs != right.crs:
                right = right.to_crs(left.crs)
            result = gpd.sjoin(left, right, how=how, predicate=predicate)
            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"Spatial join ({how}, {predicate}) 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 sjoin_gpd: {str(e)}")
            return {"status": "error", "message": str(e)}
  • Resource function listing 'sjoin_gpd' among available GeoPandas join operations, serving as tool discovery.
    @gis_mcp.resource("gis://geopandas/joins")
    def get_geopandas_joins() -> Dict[str, List[str]]:
        """List available GeoPandas join operations."""
        return {
            "operations": [
                "append_gpd",
                "merge_gpd",
                "sjoin_gpd",
                "sjoin_nearest_gpd",
                "point_in_polygon"
            ]
        }
  • src/gis_mcp/mcp.py:5-6 (registration)
    FastMCP server instance 'gis_mcp' that handles tool registration via decorators like @gis_mcp.tool().
    gis_mcp = FastMCP("GIS MCP")
Behavior2/5

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

With no annotations provided, the description carries full burden but provides minimal behavioral context. It mentions the tool uses 'geopandas.sjoin' and describes the return format, but doesn't disclose important behaviors like whether it modifies input files, memory requirements for large datasets, error handling, or performance characteristics for different spatial predicates.

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 well-structured with clear sections for Args and Returns. It's appropriately sized at 6 sentences, though the first sentence could be more front-loaded with key information. No wasted words, but the structure could be slightly more efficient.

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 has an output schema (implied by 'Returns' section), the description doesn't need to explain return values in detail. However, for a spatial join operation with 5 parameters and no annotations, the description should provide more context about prerequisites (e.g., file formats, coordinate systems), limitations, and error conditions to be fully complete.

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, the description compensates well by explaining all 5 parameters in the Args section, including their purposes and some default values. It clarifies that 'output_path' is optional and describes what each parameter represents, though it could provide more detail about valid predicate options and file format requirements.

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 tool performs a 'spatial join between two GeoDataFrames using geopandas.sjoin', specifying both the verb (spatial join) and resources (two GeoDataFrames). It distinguishes from sibling tools like 'sjoin_nearest_gpd' by specifying the standard spatial join method rather than nearest-neighbor join.

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 is provided about when to use this tool versus alternatives. While it distinguishes from 'sjoin_nearest_gpd' by not mentioning nearest joins, it doesn't explain when to choose this over other spatial operations like 'intersection', 'overlay_gpd', or 'point_in_polygon' that might serve similar purposes.

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