get_length
Calculate the length of a geometric feature using the GIS MCP Server. Input a geometry string to perform accurate spatial measurements for geospatial analysis.
Instructions
Get the length of a geometry.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| geometry | Yes |
Implementation Reference
- src/gis_mcp/shapely_functions.py:406-419 (handler)The primary handler function for the 'get_length' tool. It takes a WKT geometry string, loads it with Shapely, computes the length, and returns a dictionary with the result.@gis_mcp.tool() def get_length(geometry: str) -> Dict[str, Any]: """Get the length of a geometry.""" try: from shapely import wkt geom = wkt.loads(geometry) return { "status": "success", "length": float(geom.length), "message": "Length calculated successfully" } except Exception as e: logger.error(f"Error calculating length: {str(e)}") raise ValueError(f"Failed to calculate length: {str(e)}")
- src/gis_mcp/shapely_functions.py:406-419 (registration)The @gis_mcp.tool() decorator registers this function as an MCP tool named 'get_length'. The function signature provides the input schema.@gis_mcp.tool() def get_length(geometry: str) -> Dict[str, Any]: """Get the length of a geometry.""" try: from shapely import wkt geom = wkt.loads(geometry) return { "status": "success", "length": float(geom.length), "message": "Length calculated successfully" } except Exception as e: logger.error(f"Error calculating length: {str(e)}") raise ValueError(f"Failed to calculate length: {str(e)}")
- A resource endpoint that lists available measurement operations, including 'get_length', to inform clients of available tools.@gis_mcp.resource("gis://operations/measurements") def get_measurements() -> Dict[str, List[str]]: """List available measurement operations.""" return { "operations": [ "get_length", "get_area" ] }