Skip to main content
Glama

point_in_polygon

Check if geographic points are inside polygons using spatial analysis. This GIS tool performs spatial joins to determine point-in-polygon relationships for geospatial data.

Instructions

Check if points are inside polygons using spatial join (predicate='within'). Args: points_path: Path to the point geospatial file. polygons_path: Path to the polygon geospatial file. output_path: Optional path to save the result. Returns: Dictionary with status, message, and output info.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
points_pathYes
polygons_pathYes
output_pathNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function decorated with @gis_mcp.tool(), implementing point-in-polygon check via geopandas.sjoin with 'within' predicate. Handles file I/O, CRS alignment, result preview, and optional output saving.
    @gis_mcp.tool()
    def point_in_polygon(points_path: str, polygons_path: str, output_path: str = None) -> Dict[str, Any]:
        """
        Check if points are inside polygons using spatial join (predicate='within').
        Args:
            points_path: Path to the point geospatial file.
            polygons_path: Path to the polygon geospatial file.
            output_path: Optional path to save the result.
        Returns:
            Dictionary with status, message, and output info.
        """
        try:
            points = gpd.read_file(points_path)
            polygons = gpd.read_file(polygons_path)
            if points.crs != polygons.crs:
                polygons = polygons.to_crs(points.crs)
            result = gpd.sjoin(points, polygons, how="left", predicate="within")
            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": "Point-in-polygon test 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 point_in_polygon: {str(e)}")
            return {"status": "error", "message": str(e)}
  • MCP resource listing that registers 'point_in_polygon' as an available operation in the geopandas/joins category.
    @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"
            ]
        }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the operation but does not describe permissions needed, potential side effects (e.g., file creation), performance considerations, or error handling. This leaves significant gaps for a tool that performs spatial computations and file I/O.

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, making it easy to scan. It uses minimal sentences that directly convey necessary information without fluff, though it could be slightly more concise by integrating the method note into the main sentence.

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 (spatial analysis with file I/O), no annotations, and an output schema present, the description covers the basic operation and parameters but lacks details on behavioral aspects like error conditions or performance. The output schema likely handles return values, but more context on usage and limitations would improve completeness.

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?

The description explicitly lists and describes all three parameters ('points_path', 'polygons_path', 'output_path'), including that 'output_path' is optional. Since schema description coverage is 0%, this adds substantial meaning beyond the bare schema, clarifying what each path represents and their roles in the spatial join process.

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 ('Check if points are inside polygons') and the method ('using spatial join with predicate="within"'). It distinguishes from siblings like 'sjoin_gpd' by specifying the exact predicate used, making the purpose explicit and differentiated.

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?

The description provides no guidance on when to use this tool versus alternatives like 'sjoin_gpd' or other spatial analysis tools. It lacks context about prerequisites, such as required file formats or coordinate systems, and does not mention any exclusions or typical use cases.

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