Skip to main content
Glama

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
NameRequiredDescriptionDefault
geometry1Yes
geometry2Yes
toleranceYes

Implementation Reference

  • 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)}
  • 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)}

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mahdin75/gis-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server