Skip to main content
Glama

geodetic_to_ecef

Convert geodetic coordinates (latitude, longitude, altitude) to Earth-centered Earth-fixed (ECEF) coordinates using WGS84 ellipsoid parameters.

Instructions

Convert geodetic coordinates (lat/lon/alt) to Earth-centered Earth-fixed (ECEF) coordinates.

Args: latitude_deg: Latitude in degrees (-90 to 90) longitude_deg: Longitude in degrees (-180 to 180) altitude_m: Altitude above WGS84 ellipsoid in meters

Returns: JSON string with ECEF X, Y, Z coordinates in meters.

Raises: No exceptions are raised directly; errors are returned as formatted strings.

Note: The geodetic-to-ECEF conversion uses the WGS84 ellipsoid parameters: a = 6378137.0 m (semi-major axis, equatorial radius) f = 1/298.257223563 (flattening) e^2 = 2f - f^2 (first eccentricity squared)

The conversion equations are:
    N = a / sqrt(1 - e^2 * sin^2(lat))   (radius of curvature in prime vertical)
    X = (N + h) * cos(lat) * cos(lon)
    Y = (N + h) * cos(lat) * sin(lon)
    Z = (N * (1 - e^2) + h) * sin(lat)
where lat, lon are geodetic latitude/longitude and h is altitude above ellipsoid.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
latitude_degYes
longitude_degYes
altitude_mNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler for geodetic to ECEF conversion. Accepts latitude, longitude, altitude; delegates to integrations.frames and returns JSON response.
    def geodetic_to_ecef(
        latitude_deg: float, longitude_deg: float, altitude_m: float = 0.0
    ) -> str:
        """Convert geodetic coordinates (lat/lon/alt) to Earth-centered Earth-fixed (ECEF) coordinates.
    
        Args:
            latitude_deg: Latitude in degrees (-90 to 90)
            longitude_deg: Longitude in degrees (-180 to 180)
            altitude_m: Altitude above WGS84 ellipsoid in meters
    
        Returns:
            JSON string with ECEF X, Y, Z coordinates in meters.
    
        Raises:
            No exceptions are raised directly; errors are returned as formatted strings.
    
        Note:
            The geodetic-to-ECEF conversion uses the WGS84 ellipsoid parameters:
                a = 6378137.0 m          (semi-major axis, equatorial radius)
                f = 1/298.257223563      (flattening)
                e^2 = 2f - f^2           (first eccentricity squared)
    
            The conversion equations are:
                N = a / sqrt(1 - e^2 * sin^2(lat))   (radius of curvature in prime vertical)
                X = (N + h) * cos(lat) * cos(lon)
                Y = (N + h) * cos(lat) * sin(lon)
                Z = (N * (1 - e^2) + h) * sin(lat)
            where lat, lon are geodetic latitude/longitude and h is altitude above ellipsoid.
        """
        try:
            from ..integrations.frames import geodetic_to_ecef as _geodetic_to_ecef
    
            result = _geodetic_to_ecef(latitude_deg, longitude_deg, altitude_m)
    
            return json.dumps(
                {
                    "input": {
                        "latitude_deg": latitude_deg,
                        "longitude_deg": longitude_deg,
                        "altitude_m": altitude_m,
                    },
                    "output": {
                        "x_m": result["x_m"],
                        "y_m": result["y_m"],
                        "z_m": result["z_m"],
                    },
                    "reference_frame": "WGS84 ECEF",
                    "units": {"position": "meters"},
                },
                indent=2,
            )
    
        except ImportError:
            return "Coordinate conversion not available - geodetic module required"
        except Exception as e:
            logger.error(f"Geodetic to ECEF error: {str(e)}", exc_info=True)
            return f"Geodetic to ECEF error: {str(e)}"
  • Tool signature with type hints: latitude_deg (float, -90 to 90), longitude_deg (float, -180 to 180), altitude_m (float, default 0.0). Returns JSON string.
    def geodetic_to_ecef(
        latitude_deg: float, longitude_deg: float, altitude_m: float = 0.0
    ) -> str:
  • Integration-level geodetic_to_ecef with input validation (lat/lon bounds) and calls the manual WGS84 computation.
    def geodetic_to_ecef(
        latitude_deg: float, longitude_deg: float, altitude_m: float
    ) -> CoordinatePoint:
        """
        Convert geodetic coordinates to ECEF.
    
        Uses NumPy for efficient calculations.
    
        Args:
            latitude_deg: Latitude in degrees (-90 to +90)
            longitude_deg: Longitude in degrees (-180 to +180)
            altitude_m: Height above WGS84 ellipsoid in meters
    
        Returns:
            CoordinatePoint with ECEF coordinates
        """
        if not (-90 <= latitude_deg <= 90):
            raise ValueError("Latitude must be between -90 and +90 degrees")
        if not (-180 <= longitude_deg <= 180):
            raise ValueError("Longitude must be between -180 and +180 degrees")
    
        x, y, z = _manual_geodetic_to_ecef(latitude_deg, longitude_deg, altitude_m)
    
        return CoordinatePoint(x=x, y=y, z=z, frame="ECEF")
  • Core WGS84 geodetic-to-ECEF math: computes radius of curvature N, then ECEF x,y,z using standard closed-form formulas.
    def _manual_geodetic_to_ecef(
        lat_deg: float, lon_deg: float, alt_m: float
    ) -> tuple[float, float, float]:
        """Convert geodetic coordinates to ECEF Cartesian.
    
        Uses the WGS-84 ellipsoid formulas::
    
            x = (N + h) * cos(lat) * cos(lon)
            y = (N + h) * cos(lat) * sin(lon)
            z = (N * (1 - e^2) + h) * sin(lat)
    
        where N = a / sqrt(1 - e^2 * sin^2(lat)) is the radius of curvature
        in the prime vertical.
    
        Args:
            lat_deg: Geodetic latitude in degrees.
            lon_deg: Geodetic longitude in degrees.
            alt_m: Height above the WGS-84 ellipsoid in meters.
    
        Returns:
            Tuple of ``(x, y, z)`` ECEF coordinates in meters.
        """
        lat_rad = np.radians(lat_deg)
        lon_rad = np.radians(lon_deg)
    
        sin_lat = float(np.sin(lat_rad))
        cos_lat = float(np.cos(lat_rad))
        sin_lon = float(np.sin(lon_rad))
        cos_lon = float(np.cos(lon_rad))
    
        # Radius of curvature in the prime vertical
        # N = a / sqrt(1 - e^2 * sin^2(lat))
        N = EARTH_A / float(np.sqrt(1.0 - EARTH_E2 * sin_lat**2))
    
        # ECEF coordinates from geodetic
        x = (N + alt_m) * cos_lat * cos_lon
        y = (N + alt_m) * cos_lat * sin_lon
        z = (N * (1.0 - EARTH_E2) + alt_m) * sin_lat
    
        return x, y, z
  • Registration of geodetic_to_ecef as an MCP tool via FastMCP decorator.
    mcp.tool(geodetic_to_ecef)
Behavior4/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 details the WGS84 ellipsoid parameters, conversion equations, and notes that exceptions are not raised but errors returned as strings. This is transparent about the mathematical model and error handling, though it omits any side effects or authorization needs (likely none).

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 well-structured with sections for Args, Returns, Raises, and Note. However, it includes detailed formulas and ellipsoid parameters which, while informative, could be more concise. The first sentence efficiently captures the purpose, and the structure aids readability.

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

Completeness5/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 (3 parameters, no nested objects) and the presence of an output schema (indicated), the description covers parameters, return format, error handling, and the underlying model completely. No significant gaps remain.

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

Parameters4/5

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

The input schema has 0% description coverage, so the description is essential. It adds meaningful context beyond the schema: specifies valid ranges for latitude and longitude, explains altitude above WGS84 ellipsoid, and notes the default of 0 for altitude. This sufficiently compensates for the bare schema.

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

Purpose5/5

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

The description clearly states 'Convert geodetic coordinates (lat/lon/alt) to Earth-centered Earth-fixed (ECEF) coordinates.' This specifies the exact operation and resource, and the sibling list includes 'ecef_to_geodetic' which implicitly distinguishes the inverse direction.

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

Usage Guidelines3/5

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

The description does not explicitly state when to use this tool versus alternatives. It implies usage for geodetic-to-ECEF conversion, but does not mention the inverse tool or any conditions for choosing among sibling tools.

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/cheesejaguar/aerospace-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server