project_geometry
Transform geometric data between Coordinate Reference Systems (CRS) to ensure accurate spatial analysis and alignment in GIS workflows.
Instructions
Project a geometry between CRS.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| geometry | Yes | ||
| source_crs | Yes | ||
| target_crs | Yes |
Implementation Reference
- src/gis_mcp/pyproj_functions.py:64-84 (handler)The main handler function for the 'project_geometry' MCP tool. It parses WKT geometry, uses pyproj.Transformer to project coordinates, applies shapely.ops.transform, and returns the projected WKT geometry.@gis_mcp.tool() def project_geometry(geometry: str, source_crs: str, target_crs: str) -> Dict[str, Any]: """Project a geometry between CRS.""" try: from shapely import wkt from shapely.ops import transform from pyproj import Transformer geom = wkt.loads(geometry) transformer = Transformer.from_crs(source_crs, target_crs, always_xy=True) projected = transform(transformer.transform, geom) return { "status": "success", "geometry": projected.wkt, "source_crs": source_crs, "target_crs": target_crs, "message": "Geometry projected successfully" } except Exception as e: logger.error(f"Error projecting geometry: {str(e)}") raise ValueError(f"Failed to project geometry: {str(e)}")
- src/gis_mcp/pyproj_functions.py:9-17 (registration)Resource endpoint listing 'project_geometry' as an available CRS transformation operation.@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" ] }
- src/gis_mcp/data/land_cover.py:43-46 (helper)Helper function _project_geometry_to used in land cover tools for projecting geometries, similar logic to the main tool.def _project_geometry_to(to_crs: str, geom, from_crs: str = "EPSG:4326"): transformer = Transformer.from_crs(from_crs, to_crs, always_xy=True) return shapely_transform(lambda x, y: transformer.transform(x, y), geom)