Skip to main content
Glama

clip_vector

Clip vector geometries to a specified boundary using geospatial files. Input a geospatial file and a clipping geometry file, and optionally save the result for precise spatial analysis.

Instructions

Clip vector geometries using geopandas.clip. Args: gdf_path: Path to the input geospatial file. clip_path: Path to the clipping geometry file. output_path: Optional path to save the result. Returns: Dictionary with status, message, and output info.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
clip_pathYes
gdf_pathYes
output_pathNo

Implementation Reference

  • The handler function for the 'clip_vector' tool. It reads input GeoDataFrames, ensures matching CRS, performs clipping using gpd.clip, optionally saves the result, and returns metadata including preview.
    @gis_mcp.tool() def clip_vector(gdf_path: str, clip_path: str, output_path: str = None) -> Dict[str, Any]: """ Clip vector geometries using geopandas.clip. Args: gdf_path: Path to the input geospatial file. clip_path: Path to the clipping geometry file. output_path: Optional path to save the result. Returns: Dictionary with status, message, and output info. """ try: gdf = gpd.read_file(gdf_path) clip_gdf = gpd.read_file(clip_path) if gdf.crs != clip_gdf.crs: clip_gdf = clip_gdf.to_crs(gdf.crs) result = gpd.clip(gdf, clip_gdf) 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) preview = result.head(5).to_dict(orient="records") return { "status": "success", "message": "Clip 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 clip_vector: {str(e)}") return {"status": "error", "message": str(e)}

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