Skip to main content
Glama

get_utm_zone

Determine the UTM zone for geographic coordinates to enable accurate geospatial analysis and coordinate transformations in mapping applications.

Instructions

Get UTM zone for given coordinates.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
coordinatesYes

Implementation Reference

  • The handler function that implements the get_utm_zone tool logic using pyproj to query UTM CRS info and extract the zone number from coordinates.
    @gis_mcp.tool()
    def get_utm_zone(coordinates: List[float]) -> Dict[str, Any]:
        """Get UTM zone for given coordinates."""
        try:
            import pyproj
            from pyproj.database import query_utm_crs_info
            lon, lat = coordinates
            crs_info_list = query_utm_crs_info(
                datum_name="WGS 84",  # Use "WGS 84" with space as per standard
                area_of_interest=pyproj.aoi.AreaOfInterest(
                    west_lon_degree=lon,
                    south_lat_degree=lat,
                    east_lon_degree=lon,
                    north_lat_degree=lat
                )
            )
            if not crs_info_list:
                raise ValueError("No UTM CRS found for the given coordinates")
            
            # Create CRS from the first matching CRSInfo
            crs_obj = pyproj.CRS.from_authority(crs_info_list[0].auth_name, crs_info_list[0].code)
            # Extract zone number from CRS name (e.g., "WGS 84 / UTM zone 10N" -> 10)
            import re
            zone_match = re.search(r'zone\s+(\d+)', crs_info_list[0].name, re.IGNORECASE)
            if zone_match:
                zone = int(zone_match.group(1))
            else:
                # Fallback: try to extract from authority code
                # EPSG codes for UTM: 32601-32660 (north), 32701-32760 (south)
                code = int(crs_info_list[0].code)
                if 32601 <= code <= 32660:  # Northern hemisphere
                    zone = code - 32600
                elif 32701 <= code <= 32760:  # Southern hemisphere
                    zone = code - 32700
                else:
                    raise ValueError("Could not extract valid UTM zone number from CRS")
            
            if zone < 1 or zone > 60:
                raise ValueError(f"Invalid UTM zone number: {zone}")
            
            return {
                "status": "success",
                "zone": zone,
                "message": "UTM zone retrieved successfully"
            }
        except Exception as e:
            logger.error(f"Error getting UTM zone: {str(e)}")
            raise ValueError(f"Failed to get UTM zone: {str(e)}")
  • MCP resource that lists 'get_utm_zone' among available CRS information operations, aiding tool discovery.
    @gis_mcp.resource("gis://crs/info")
    def get_crs_info_operations() -> Dict[str, List[str]]:
        """List available CRS information operations."""
        return {
            "operations": [
                "get_crs_info",
                "get_available_crs",
                "get_utm_zone",
                "get_utm_crs",
                "get_geocentric_crs"
            ]
        }
  • Type hints and docstring define the input schema (coordinates: List[float]) and output schema (Dict[str, Any]).
    def get_utm_zone(coordinates: List[float]) -> Dict[str, Any]:

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