get_centroid
Calculate the centroid of a geometry using the GIS MCP Server for precise geospatial analysis, enabling accurate geometric operations in AI-driven workflows.
Instructions
Get the centroid of a geometry.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| geometry | Yes |
Implementation Reference
- src/gis_mcp/shapely_functions.py:237-251 (handler)The get_centroid tool handler: decorated with @gis_mcp.tool(), takes WKT geometry string, computes centroid using Shapely.geometry.centroid, returns WKT of centroid or raises error.@gis_mcp.tool() def get_centroid(geometry: str) -> Dict[str, Any]: """Get the centroid of a geometry.""" try: from shapely import wkt geom = wkt.loads(geometry) result = geom.centroid return { "status": "success", "geometry": result.wkt, "message": "Centroid calculated successfully" } except Exception as e: logger.error(f"Error calculating centroid: {str(e)}") raise ValueError(f"Failed to calculate centroid: {str(e)}")
- Helper resource listing geometric property operations available via MCP, including get_centroid.@gis_mcp.resource("gis://operations/geometric") def get_geometric_properties() -> Dict[str, List[str]]: """List available geometric property operations.""" return { "operations": [ "convex_hull", "envelope", "minimum_rotated_rectangle", "get_centroid", "get_bounds", "get_coordinates", "get_geometry_type" ] }
- src/gis_mcp/shapely_functions.py:237-237 (registration)MCP tool registration decorator for get_centroid.@gis_mcp.tool()