geodetic_to_ecef
Convert latitude, longitude, and altitude coordinates to Earth-centered Earth-fixed (ECEF) coordinates for flight planning and aerospace calculations.
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 coordinates
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| latitude_deg | Yes | ||
| longitude_deg | Yes | ||
| altitude_m | No |
Implementation Reference
- aerospace_mcp/tools/frames.py:40-80 (handler)MCP tool handler: wraps library function, formats input/output as JSON with metadata.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 coordinates """ 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)}"
- Pydantic models for input (GeodeticPoint) and output (CoordinatePoint) validation used by the library function.class CoordinatePoint(BaseModel): """A point in 3D space with metadata.""" x: float = Field(..., description="X coordinate (m)") y: float = Field(..., description="Y coordinate (m)") z: float = Field(..., description="Z coordinate (m)") frame: str = Field(..., description="Coordinate frame") epoch: str | None = Field(None, description="Epoch (ISO format)") class GeodeticPoint(BaseModel): """Geodetic coordinates.""" latitude_deg: float = Field(..., description="Latitude in degrees") longitude_deg: float = Field(..., description="Longitude in degrees") altitude_m: float = Field(..., description="Height above ellipsoid (m)")
- aerospace_mcp/fastmcp_server.py:96-96 (registration)Registers the geodetic_to_ecef handler function with the FastMCP server.mcp.tool(geodetic_to_ecef)
- Core mathematical implementation: converts geodetic (lat, lon, alt) to ECEF (x,y,z) using WGS84 ellipsoid formula.def _manual_geodetic_to_ecef( lat_deg: float, lon_deg: float, alt_m: float ) -> tuple[float, float, float]: """ Convert geodetic to ECEF coordinates. Returns (x, y, z) in meters. """ lat_rad = math.radians(lat_deg) lon_rad = math.radians(lon_deg) sin_lat = math.sin(lat_rad) cos_lat = math.cos(lat_rad) sin_lon = math.sin(lon_rad) cos_lon = math.cos(lon_rad) # Radius of curvature in prime vertical N = EARTH_A / math.sqrt(1.0 - EARTH_E2 * sin_lat**2) 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
- Library wrapper: validates inputs and calls manual converter, returns typed CoordinatePoint.def geodetic_to_ecef( latitude_deg: float, longitude_deg: float, altitude_m: float ) -> CoordinatePoint: """ Convert geodetic coordinates to ECEF. 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")