transform_coordinates
Convert spatial coordinates between Coordinate Reference Systems (CRS) for accurate geospatial analysis. Define source and target CRS to enable precise coordinate transformations.
Instructions
Transform coordinates between CRS.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| coordinates | Yes | ||
| source_crs | Yes | ||
| target_crs | Yes |
Implementation Reference
- src/gis_mcp/pyproj_functions.py:44-62 (handler)The primary handler function for the 'transform_coordinates' tool. It takes a list of two floats (x,y), source CRS, and target CRS, uses pyproj.Transformer to perform the transformation, and returns a success dict with transformed coordinates or raises an error.@gis_mcp.tool() def transform_coordinates(coordinates: List[float], source_crs: str, target_crs: str) -> Dict[str, Any]: """Transform coordinates between CRS.""" try: from pyproj import Transformer transformer = Transformer.from_crs(source_crs, target_crs, always_xy=True) x, y = coordinates x_transformed, y_transformed = transformer.transform(x, y) return { "status": "success", "coordinates": [x_transformed, y_transformed], "source_crs": source_crs, "target_crs": target_crs, "message": "Coordinates transformed successfully" } except Exception as e: logger.error(f"Error transforming coordinates: {str(e)}") raise ValueError(f"Failed to transform coordinates: {str(e)}")
- src/gis_mcp/pyproj_functions.py:9-17 (registration)MCP resource that registers and lists 'transform_coordinates' as an available operation under CRS transformations for tool discovery.@gis_mcp.resource("gis://crs/transformations") def get_crs_transformations() -> Dict[str, List[str]]: """List available CRS transformation operations.""" return { "operations": [ "transform_coordinates", "project_geometry" ] }
- Function signature defining the input schema (coordinates: List[float], source_crs: str, target_crs: str) and output (Dict[str, Any]) for the tool.def transform_coordinates(coordinates: List[float], source_crs: str, target_crs: str) -> Dict[str, Any]: