dissolve_gpd
Dissolve geospatial geometries by attribute to simplify vector data, reducing complexity by merging features with matching values in a specified column.
Instructions
Dissolve geometries by attribute using geopandas.dissolve. Args: gdf_path: Path to the geospatial file. by: Column to dissolve by (optional). output_path: Optional path to save the result. Returns: Dictionary with status, message, and output info.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| gdf_path | Yes | ||
| by | No | ||
| output_path | No |
Implementation Reference
- The main handler function for the 'dissolve_gpd' MCP tool, decorated with @gis_mcp.tool(). It reads a GeoDataFrame, dissolves geometries by the specified attribute, optionally saves to output_path, and returns stats and preview.@gis_mcp.tool() def dissolve_gpd(gdf_path: str, by: str = None, output_path: str = None) -> Dict[str, Any]: """ Dissolve geometries by attribute using geopandas.dissolve. Args: gdf_path: Path to the geospatial file. by: Column to dissolve by (optional). output_path: Optional path to save the result. Returns: Dictionary with status, message, and output info. """ try: gdf = gpd.read_file(gdf_path) result = gdf.dissolve(by=by) 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"Dissolve 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 dissolve_gpd: {str(e)}") return {"status": "error", "message": str(e)}
- src/gis_mcp/geopandas_functions.py:13-26 (registration)Resource listing that includes 'dissolve_gpd' as an available GeoPandas operation.@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" ] }