nearest_point_on_geometry
Identify the nearest point on one geometry relative to another using Well-Known Text (WKT) inputs. Outputs the closest point location as WKT for geospatial analysis and decision-making.
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-536 (handler)The handler function for the 'nearest_point_on_geometry' tool. It takes two WKT geometry strings, uses shapely.ops.nearest_points to find the closest point on the second geometry to the first, and returns the result as WKT in a status dictionary.@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 function that lists 'nearest_point_on_geometry' as one of the available Shapely utility operations, serving as a tool discovery/registration mechanism.@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" ] }