explode_gpd
Split multi-part geospatial geometries into individual components to simplify analysis or processing. Input a geospatial file path and optionally save the result to a specified output location.
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 from file, explodes multi-part geometries to single parts using gpd.explode(), optionally exports result, and returns success metadata with preview or error details.@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) preview = result.head(5).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)}
- MCP resource listing available GeoPandas operations, including 'explode_gpd', 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" ] }
- src/gis_mcp/__init__.py:5-10 (registration)Import of geopandas_functions module in __init__.py, which triggers tool registration via decorators when the package is imported.from .geopandas_functions import * from .shapely_functions import * from .rasterio_functions import * from .pyproj_functions import * from .pysal_functions import * from .save_tool import *