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
| Name | Required | Description | Default |
|---|---|---|---|
| latitude_deg | Yes | ||
| longitude_deg | Yes | ||
| altitude_m | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- aerospace_mcp/tools/frames.py:53-109 (handler)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)}" - aerospace_mcp/tools/frames.py:53-55 (schema)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 - aerospace_mcp/fastmcp_server.py:197-197 (registration)Registration of geodetic_to_ecef as an MCP tool via FastMCP decorator.
mcp.tool(geodetic_to_ecef)