Skip to main content
Glama

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

Implementation Reference

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

Other Tools

Related Tools

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