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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

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"
            ]
        }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions the method ('shapely.ops.nearest_points') and return format, but lacks behavioral details: it doesn't specify error handling (e.g., for invalid geometries), performance considerations, or dependencies (e.g., shapely library). For a tool with no annotations, this is insufficient to fully inform an agent about its operational traits.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded: the first sentence states the purpose clearly, followed by structured sections for Args and Returns. There's minimal waste, though the 'Args:' and 'Returns:' labels could be integrated more seamlessly. Overall, it's efficient and easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (2 parameters, no annotations, but has an output schema), the description is partially complete. It covers purpose, parameters, and return format, but lacks usage guidelines, behavioral context, and error handling. The output schema likely details the return dictionary, reducing the need for return value explanation, but other gaps remain, making it adequate but with clear omissions.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, but the description compensates by explaining parameters: 'geometry1: WKT string of the first geometry (e.g., a point)' and 'geometry2: WKT string of the second geometry.' It adds meaning beyond the bare schema by specifying format (WKT) and providing an example. However, it doesn't detail constraints (e.g., valid geometry types) or edge cases, so it only partially fills the coverage gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Find the nearest point on geometry2 to geometry1 using shapely.ops.nearest_points.' It specifies the verb ('Find'), resources ('geometry2' and 'geometry1'), and method ('shapely.ops.nearest_points'). However, it does not explicitly differentiate from sibling tools like 'sjoin_nearest_gpd' or 'distance_band_weights', which may have overlapping spatial functions, so it misses full sibling distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It lacks context on prerequisites (e.g., valid WKT strings), exclusions (e.g., not for 3D geometries), or comparisons to siblings like 'sjoin_nearest_gpd' or 'calculate_geodetic_distance'. Usage is implied by the function name but not explicitly stated, leaving gaps for an AI agent.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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