write_file_gpd
Convert and save GeoDataFrame to geospatial file formats like Shapefile, GeoJSON, or GPKG using specified driver, enabling efficient geospatial data export.
Instructions
Export a GeoDataFrame to a file (Shapefile, GeoJSON, GPKG, etc.).
Args:
gdf_path: Path to the input geospatial file.
output_path: Path to save the exported file.
driver: Optional OGR driver name (e.g., 'ESRI Shapefile', 'GeoJSON', 'GPKG').
Returns:
Dictionary with status and message.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| driver | No | ||
| gdf_path | Yes | ||
| output_path | Yes |
Implementation Reference
- The primary handler function decorated with @gis_mcp.tool(), implementing the logic to read a GeoDataFrame and write it to a specified output file using GeoPandas' to_file method.@gis_mcp.tool() def write_file_gpd(gdf_path: str, output_path: str, driver: str = None) -> Dict[str, Any]: """ Export a GeoDataFrame to a file (Shapefile, GeoJSON, GPKG, etc.). Args: gdf_path: Path to the input geospatial file. output_path: Path to save the exported file. driver: Optional OGR driver name (e.g., 'ESRI Shapefile', 'GeoJSON', 'GPKG'). Returns: Dictionary with status and message. """ try: gdf = gpd.read_file(gdf_path) output_path_resolved = resolve_path(output_path, relative_to_storage=True) output_path_resolved.parent.mkdir(parents=True, exist_ok=True) kwargs = {"driver": driver} if driver else {} gdf.to_file(str(output_path_resolved), **kwargs) return { "status": "success", "message": f"GeoDataFrame exported to '{output_path_resolved}' successfully.", "output_path": str(output_path_resolved), "crs": str(gdf.crs), "num_features": len(gdf), "columns": list(gdf.columns), } except Exception as e: logger.error(f"Error in write_file_gpd: {str(e)}") return {"status": "error", "message": str(e)}
- src/gis_mcp/geopandas_functions.py:13-26 (registration)Resource function listing 'write_file_gpd' as one of the available GeoPandas I/O operations.@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" ] }