Skip to main content
Glama

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

Implementation Reference

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

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