geometry_to_geojson
Convert WKT geometry strings into GeoJSON format using Shapely's mapping function. Simplifies geospatial data transformation for integration with web mapping tools and GIS workflows.
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
| Name | Required | Description | Default |
|---|---|---|---|
| geometry | Yes |
Implementation Reference
- src/gis_mcp/shapely_functions.py:559-580 (handler)The main handler function for the 'geometry_to_geojson' tool, decorated with @gis_mcp.tool() for MCP registration. Converts WKT geometry to GeoJSON using Shapely's mapping.@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 listing 'geometry_to_geojson' among available Shapely utility operations.@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" ] }