explode_gpd
Split multi-part geospatial geometries into individual components for analysis. Converts complex geographic data into separate features using geopandas.explode.
Instructions
Split multi-part geometries into single parts using geopandas.explode. Args: gdf_path: Path to the geospatial file. 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 | ||
| output_path | No |
Implementation Reference
- Core implementation of the 'explode_gpd' MCP tool: loads GeoDataFrame, explodes multi-part geometries, optionally saves output, returns metadata and preview.@gis_mcp.tool() def explode_gpd(gdf_path: str, output_path: str = None) -> Dict[str, Any]: """ Split multi-part geometries into single parts using geopandas.explode. Args: gdf_path: Path to the geospatial file. 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.explode(index_parts=True, ignore_index=True) 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": "Explode 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 explode_gpd: {str(e)}") return {"status": "error", "message": str(e)}
- src/gis_mcp/__init__.py:5-5 (registration)Import of geopandas_functions module in __init__.py, which triggers the @gis_mcp.tool() decorator to register the 'explode_gpd' tool.from .geopandas_functions import *
- MCP resource listing GeoPandas I/O tools, including 'explode_gpd', discoverable at gis://geopandas/io.@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" ] }