snap_geometry
Aligns one geometry to another within a specified tolerance to correct positional inaccuracies in spatial data.
Instructions
Snap one geometry to another using shapely.ops.snap. Args: geometry1: WKT string of the geometry to be snapped. geometry2: WKT string of the reference geometry. tolerance: Distance tolerance for snapping. Returns: Dictionary with status, message, and snapped geometry as WKT.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| geometry1 | Yes | ||
| geometry2 | Yes | ||
| tolerance | Yes |
Implementation Reference
- src/gis_mcp/shapely_functions.py:486-511 (handler)The core handler function for the 'snap_geometry' tool. It is registered via the @gis_mcp.tool() decorator and implements snapping two geometries using Shapely's snap operation with the given tolerance. Includes input validation implicitly through type hints and docstring, and returns WKT geometry or error.@gis_mcp.tool() def snap_geometry(geometry1: str, geometry2: str, tolerance: float) -> Dict[str, Any]: """ Snap one geometry to another using shapely.ops.snap. Args: geometry1: WKT string of the geometry to be snapped. geometry2: WKT string of the reference geometry. tolerance: Distance tolerance for snapping. Returns: Dictionary with status, message, and snapped geometry as WKT. """ try: from shapely import wkt from shapely.ops import snap geom1 = wkt.loads(geometry1) geom2 = wkt.loads(geometry2) snapped = snap(geom1, geom2, tolerance) return { "status": "success", "geometry": snapped.wkt, "message": "Geometry snapped successfully" } except Exception as e: logger.error(f"Error in snap_geometry: {str(e)}") return {"status": "error", "message": str(e)}
- src/gis_mcp/shapely_functions.py:82-93 (registration)MCP resource that lists 'snap_geometry' among available Shapely utility operations, serving as a discovery mechanism for the tool.@gis_mcp.resource("gis://operations/shapely_util") def get_shapely_util_operations() -> Dict[str, List[str]]: """List available Shapely utility/advanced operations.""" return { "operations": [ "snap_geometry", "nearest_point_on_geometry", "normalize_geometry", "geometry_to_geojson", "geojson_to_geometry" ] }
- Error logging specific to snap_geometry, but minor.logger.error(f"Error in snap_geometry: {str(e)}") return {"status": "error", "message": str(e)}