Skip to main content
Glama

clip_vector

Extract vector geometries within specified boundaries by clipping spatial data files. Use this tool to isolate geographic features for focused analysis in GIS workflows.

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
gdf_pathYes
clip_pathYes
output_pathNo

Implementation Reference

  • The core implementation of the clip_vector tool. Loads GeoDataFrames from input paths, aligns CRS if necessary, performs geometric clipping using gpd.clip, optionally saves output, and returns metadata with a 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) # 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": "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)}
  • The @gis_mcp.tool() decorator registers the clip_vector function as an MCP tool.
    @gis_mcp.tool()
  • The gis://geopandas/io resource lists 'clip_vector' among available GeoPandas operations, serving as tool discovery/schema.
    @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" ] }

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