nearest_point_on_geometry
Calculate the closest location on one geographic feature to another using WKT geometry inputs for spatial analysis.
Instructions
Find the nearest point on geometry2 to geometry1 using shapely.ops.nearest_points. Args: geometry1: WKT string of the first geometry (e.g., a point). geometry2: WKT string of the second geometry. Returns: Dictionary with status, message, and the nearest point as WKT.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| geometry1 | Yes | ||
| geometry2 | Yes |
Implementation Reference
- src/gis_mcp/shapely_functions.py:512-535 (handler)The handler function for the 'nearest_point_on_geometry' tool. It takes two WKT geometry strings, uses Shapely's nearest_points to find the closest point on the second geometry to the first, and returns the result as WKT or error.@gis_mcp.tool() def nearest_point_on_geometry(geometry1: str, geometry2: str) -> Dict[str, Any]: """ Find the nearest point on geometry2 to geometry1 using shapely.ops.nearest_points. Args: geometry1: WKT string of the first geometry (e.g., a point). geometry2: WKT string of the second geometry. Returns: Dictionary with status, message, and the nearest point as WKT. """ try: from shapely import wkt from shapely.ops import nearest_points geom1 = wkt.loads(geometry1) geom2 = wkt.loads(geometry2) p1, p2 = nearest_points(geom1, geom2) return { "status": "success", "nearest_point": p2.wkt, "message": "Nearest point found successfully" } except Exception as e: logger.error(f"Error in nearest_point_on_geometry: {str(e)}") return {"status": "error", "message": str(e)}
- src/gis_mcp/shapely_functions.py:82-93 (registration)Resource handler that lists 'nearest_point_on_geometry' among the available Shapely utility operations, effectively registering or documenting its availability.@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" ] }