Skip to main content
Glama

geometry_to_geojson

Convert WKT geometry strings to GeoJSON format for geospatial analysis in GIS applications.

Instructions

Convert a Shapely geometry (WKT) to GeoJSON using shapely.geometry.mapping. Args: geometry: WKT string of the geometry. Returns: Dictionary with status, message, and GeoJSON representation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
geometryYes

Implementation Reference

  • The handler function for the 'geometry_to_geojson' tool. Converts a WKT geometry string to GeoJSON using Shapely's mapping function.
    @gis_mcp.tool()
    def geometry_to_geojson(geometry: str) -> Dict[str, Any]:
        """
        Convert a Shapely geometry (WKT) to GeoJSON using shapely.geometry.mapping.
        Args:
            geometry: WKT string of the geometry.
        Returns:
            Dictionary with status, message, and GeoJSON representation.
        """
        try:
            from shapely import wkt
            from shapely.geometry import mapping
            geom = wkt.loads(geometry)
            geojson = mapping(geom)
            return {
                "status": "success",
                "geojson": geojson,
                "message": "Geometry converted to GeoJSON successfully"
            }
        except Exception as e:
            logger.error(f"Error in geometry_to_geojson: {str(e)}")
            return {"status": "error", "message": str(e)}
  • Resource handler that lists 'geometry_to_geojson' as an available Shapely utility operation.
    @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