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

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" ] }

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