Skip to main content
Glama

get_centroid

Calculate the central point of a geometry to identify its geographic center for mapping and spatial analysis.

Instructions

Get the centroid of a geometry.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
geometryYes

Implementation Reference

  • The main handler function for the 'get_centroid' tool. It takes a WKT string representing a geometry, uses Shapely to compute its centroid, and returns the centroid geometry as WKT in a structured response dictionary. Errors are logged and raised.
    @gis_mcp.tool()
    def get_centroid(geometry: str) -> Dict[str, Any]:
        """Get the centroid of a geometry."""
        try:
            from shapely import wkt
            geom = wkt.loads(geometry)
            result = geom.centroid
            return {
                "status": "success",
                "geometry": result.wkt,
                "message": "Centroid calculated successfully"
            }
        except Exception as e:
            logger.error(f"Error calculating centroid: {str(e)}")
            raise ValueError(f"Failed to calculate centroid: {str(e)}")

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