calculate_distance
Calculate great circle distance between two geographic coordinates for flight planning and aviation route analysis.
Instructions
Calculate great circle distance between two points.
Args: lat1: Latitude of first point in degrees lon1: Longitude of first point in degrees lat2: Latitude of second point in degrees lon2: Longitude of second point in degrees
Returns: JSON string with distance information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| lat1 | Yes | ||
| lon1 | Yes | ||
| lat2 | Yes | ||
| lon2 | Yes |
Implementation Reference
- aerospace_mcp/tools/core.py:217-251 (handler)The handler function for the 'calculate_distance' tool. It takes two pairs of latitude/longitude coordinates and computes the great circle distance, bearings, and returns a formatted JSON string using the great_circle_points helper.def calculate_distance(lat1: float, lon1: float, lat2: float, lon2: float) -> str: """Calculate great circle distance between two points. Args: lat1: Latitude of first point in degrees lon1: Longitude of first point in degrees lat2: Latitude of second point in degrees lon2: Longitude of second point in degrees Returns: JSON string with distance information """ try: # Calculate great circle route route = great_circle_points( lat1, lon1, lat2, lon2, step_km=1000000 ) # Single segment return json.dumps( { "distance_km": route["distance_km"], "distance_nm": route["distance_nm"], "initial_bearing_deg": route["initial_bearing_deg"], "final_bearing_deg": route["final_bearing_deg"], "coordinates": { "start": {"lat": lat1, "lon": lon1}, "end": {"lat": lat2, "lon": lon2}, }, }, indent=2, ) except Exception as e: return f"Distance calculation error: {str(e)}"
- aerospace_mcp/fastmcp_server.py:86-86 (registration)Registration of the calculate_distance tool in the FastMCP server using mcp.tool().mcp.tool(calculate_distance)
- aerospace_mcp/core.py:169-181 (helper)The great_circle_points helper function that performs the core geodesic calculation using geographiclib, generating points along the great circle and total distance. Used by the calculate_distance handler.def great_circle_points( lat1: float, lon1: float, lat2: float, lon2: float, step_km: float ) -> tuple[list[tuple[float, float]], float]: g = Geodesic.WGS84.Inverse(lat1, lon1, lat2, lon2) dist_m = g["s12"] line = Geodesic.WGS84.Line(lat1, lon1, g["azi1"]) n = max(1, int(math.ceil((dist_m / 1000.0) / step_km))) pts = [] for i in range(n + 1): s = min(dist_m, (dist_m * i) / n) p = line.Position(s) pts.append((p["lat2"], p["lon2"])) return pts, dist_m / 1000.0