translate_geometry
Move a geometry by specified offsets in X, Y, and optionally Z directions to reposition spatial features in GIS analysis.
Instructions
Translate a geometry.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| geometry | Yes | ||
| xoff | Yes | ||
| yoff | Yes | ||
| zoff | No |
Implementation Reference
- src/gis_mcp/shapely_functions.py:335-351 (handler)The core handler function for the 'translate_geometry' MCP tool. It parses WKT input geometry, applies translation using shapely.affinity.translate with xoff, yoff, and optional zoff offsets, and returns the resulting WKT geometry in a success response dictionary. Errors are logged and raised.@gis_mcp.tool() def translate_geometry(geometry: str, xoff: float, yoff: float, zoff: float = 0.0) -> Dict[str, Any]: """Translate a geometry.""" try: from shapely import wkt from shapely.affinity import translate geom = wkt.loads(geometry) result = translate(geom, xoff=xoff, yoff=yoff, zoff=zoff) return { "status": "success", "geometry": result.wkt, "message": "Geometry translated successfully" } except Exception as e: logger.error(f"Error translating geometry: {str(e)}") raise ValueError(f"Failed to translate geometry: {str(e)}")
- Helper resource endpoint that lists available geometric transformation operations, including 'translate_geometry', for discovery purposes.def get_transformations() -> Dict[str, List[str]]: """List available geometric transformations.""" return { "operations": [ "rotate_geometry", "scale_geometry", "translate_geometry" ] }
- src/gis_mcp/shapely_functions.py:335-351 (registration)The @gis_mcp.tool() decorator registers the translate_geometry function as an MCP tool, with schema inferred from type hints and docstring.@gis_mcp.tool() def translate_geometry(geometry: str, xoff: float, yoff: float, zoff: float = 0.0) -> Dict[str, Any]: """Translate a geometry.""" try: from shapely import wkt from shapely.affinity import translate geom = wkt.loads(geometry) result = translate(geom, xoff=xoff, yoff=yoff, zoff=zoff) return { "status": "success", "geometry": result.wkt, "message": "Geometry translated successfully" } except Exception as e: logger.error(f"Error translating geometry: {str(e)}") raise ValueError(f"Failed to translate geometry: {str(e)}")