read_file_gpd
Extract statistics and preview data from geospatial files using a GIS MCP Server tool designed for efficient file analysis and geospatial operations.
Instructions
Reads a geospatial file and returns stats and a data preview.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes |
Implementation Reference
- src/gis_mcp/geopandas_functions.py:41-69 (handler)The core handler function for the 'read_file_gpd' MCP tool. It loads geospatial files using geopandas.read_file, computes metadata (columns, dtypes, row/column counts, CRS, bounds), provides a preview of the first 5 rows, and returns structured results or error info. Registered via @gis_mcp.tool() decorator.@gis_mcp.tool() def read_file_gpd(file_path: str) -> Dict[str, Any]: """Reads a geospatial file and returns stats and a data preview.""" try: if not os.path.exists(file_path): raise FileNotFoundError(f"File not found: {file_path}") gdf = gpd.read_file(file_path) preview = gdf.head(5).to_dict(orient="records") return { "status": "success", "columns": list(gdf.columns), "column_types": gdf.dtypes.astype(str).to_dict(), "num_rows": len(gdf), "num_columns": gdf.shape[1], "crs": str(gdf.crs), "bounds": gdf.total_bounds.tolist(), # [minx, miny, maxx, maxy] "preview": preview, "message": f"File loaded successfully with {len(gdf)} rows and {gdf.shape[1]} columns" } except Exception as e: logger.error(f"Error reading file: {str(e)}") return { "status": "error", "message": f"Failed to read file: {str(e)}" }
- Helper resource that lists available GeoPandas I/O tools, including 'read_file_gpd', for discovery purposes.@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" ] }