read_file_gpd
Read geospatial files to extract statistics and preview data for analysis in GIS workflows.
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-72 (handler)The core handler function for the 'read_file_gpd' tool. It uses geopandas.read_file to load the geospatial file, computes summary statistics, creates a preview with geometry converted to WKT for JSON serialization, and returns a structured dictionary or error response.@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) # Convert geometry to WKT for serialization preview_df = gdf.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", "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)}" }
- src/gis_mcp/main.py:65-72 (registration)Import of the geopandas_functions module in the main entry point, which executes the module-level decorators (@gis_mcp.tool()) to register the 'read_file_gpd' tool with the FastMCP server instance.# Import tool modules to register MCP tools via decorators from . import ( geopandas_functions, shapely_functions, rasterio_functions, pyproj_functions, pysal_functions, )
- src/gis_mcp/mcp.py:5-5 (registration)Definition of the FastMCP server instance 'gis_mcp' that provides the @tool() and @resource() decorators used to register the 'read_file_gpd' tool.gis_mcp = FastMCP("GIS MCP")
- MCP resource that lists 'read_file_gpd' as one of the available GeoPandas I/O operations, serving as a tool discovery/schema endpoint.@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" ] }