I am working on an aviation project, in which I need to plot a great circle route between departure and destination airports.

Here is a static JSON structure I am using, where the user enters KBTP as start and KMYR as destination, I need to generate a JSON array with the JSON object structure show below with all possible way-points.

Single Object:

"icao_id": "KBTP",
"faa_facility_name": "PITTSBURGH/BUTLER RGNL",
"lat": 40.7766,
"lng": -79.9511,
"elapsed_nm": 0,
"crosstrack_nm": 0,
"total_nm": 428.091462575553,
"forecast": [
    "forecast_ts": "2019-12-31T16:00:00",
    "tmp": 35,
    "dpt": 26,
    "cld": "OV",
    "wdr": 23,
    "wsp": 17,
    "wgs": 24,
    "gsp": 7,
    "xwd": 6.4,
    "xwg": 9,
    "ppo": 57,
    "lp1": 0,
    "cp1": 1,
    "poz": 0,
    "pos": 89,
    "typ": "S",
    "cig": 4,
    "vis": 6,
    "obv": "N",
    "rlh": 69,
    "fzl": 0,
    "fzc": 1,
    "fzp": 0,
    "sno": 51,
    "t01": 0,
    "frl": 2

I looked at few libraries, but not sure if those are the right ones for me to achieve what I am looking for? https://geographiclib.sourceforge.io/html/js/tutorial-3-examples.html#waypoints

For Example: see this https://www.iflightplanner.com/aviationcharts/ If I enter two Airports and click on search KBTP, KMYR it gives the data I am looking for

Here is their API https://www.iflightplanner.com/WebServices/MapsService.asmx/GetRoute if you pass KBTP, KMYR it gives full route with way points (airports)

Can Someone help me on getting similar data?

I tried something like this

public async Task<List<Airport>> Waypoints(int noOfPoints, string startIcaoId, string endIcaoId)
        if (_airports == null || !_airports.Any())
            _airports = await _airportCollection.Find(_ => true).ToListAsync();
        var waypoints = new List<Airport>();
        var allOwnerTypes = new List<string> {
            "PUBLICLY OWNED" };
        var onlyPbulicAirports = _airports.Where(x => allOwnerTypes.Any(o => x.OwnershipType == o)).ToList();
        var start = _airports.FirstOrDefault(x => x.IcaoId == startIcaoId);
        var end = _airports.FirstOrDefault(x => x.IcaoId == endIcaoId);


        var startCoordinates = new GeoCoordinate(start.Latitude, start.Longitude);
        var endCoordinates = new GeoCoordinate(end.Latitude, end.Longitude);
        var fullRouteDistance = startCoordinates.GetDistanceTo(endCoordinates);
        double minimumFar = 0;
        if (noOfPoints > 0)
            minimumFar = (fullRouteDistance / noOfPoints) * .9;

        double lastDistance = fullRouteDistance;
        GeoCoordinate currentPoint = startCoordinates;
        while (waypoints.Last().IcaoId != end.IcaoId)
            var skipTrackedWaypoints = onlyPbulicAirports.Where(x => !waypoints.Select(x => x.IcaoId).Contains(x.IcaoId)).ToList();
            currentPoint = skipTrackedWaypoints
                .Select(x => new GeoCoordinate(x.Latitude, x.Longitude))
                .Where(x => currentPoint.GetDistanceTo(x) >= minimumFar
                //&& currentPoint.GetDistanceTo(x) < lastDistance
                 && x.GetDistanceTo(endCoordinates) < lastDistance
                && currentPoint.GetDistanceTo(x) < fullRouteDistance)
                .OrderBy(x => currentPoint.GetDistanceTo(x))
            if (currentPoint == null)
            lastDistance = currentPoint.GetDistanceTo(endCoordinates);

            var nextAirport = _airports.FirstOrDefault(x => x.Latitude == currentPoint.Latitude
             && x.Longitude == currentPoint.Longitude);

            waypoints.Add(new Airport
                IcaoId = nextAirport.IcaoId,
                FaaId = nextAirport.FaaId,
                Name = nextAirport.Name,
                Latitude = nextAirport.Latitude,
                Longitude = nextAirport.Longitude,
                Distance = lastDistance
        return waypoints;
  • 1
    The library you linked looks fine (there are lots of ways to do this), but when you say "all waypoints", you realize there are an infinite number of them, right? Are you looking for a formula to generate these or something? – barrycarter Jan 2 at 18:28
  • @barrycarter if you see my sample doc in the question jsonblob.com/52520038-2d84-11ea-96d0-6b9bec6d0f16 for those departure and destination, I got 14-15 way points (shortest distance to fly from start to end) I am trying to find a way to calculate that. – HaBo Jan 3 at 7:49
  • OK, so you're looking for airports (or weather reporting stations or whatever) that are close to the great circle path? Not just pairs of latitudes and longitudes? – barrycarter Jan 4 at 1:16
  • Airports between start and end airport – HaBo Jan 6 at 13:20
  • @barrycarter updated my question with other example – HaBo Jan 6 at 13:52

This is not an answer, but I've written a very basic proof-of-concept page at https://barrycarter.github.io/pages/REPL/WAYPOINTS/ which computes any number of FAA facility waypoints between a given pair of longitudes and latitudes. Notes:

  • Source code: https://github.com/barrycarter/pages/tree/master/REPL/WAYPOINTS

  • The source code is in JavaScript, and all files you need to run it are in the source code above. The code is entirely client-side and does not make any server connections. If you download it, you should be able to run it even without an Internet connection.

  • The functions I use are in bclib-staging.js and bclib.js and should be fairly easy to port to other languages.

  • The file stations.js is a JSON-ification of https://www.faa.gov/airports/airport_safety/airportdata_5010/menu/nfdcfacilitiesexport.cfm?Region=&District=&State=&County=&City=&Use=&Certification=

  • The file above only includes FAA facilities, which are pretty much limited to the United States (though this does include the American Samoa, Guam, etc), so, once you get away from the United States, the nearest stations can be quite far away.

  • If you or anyone has a better list I can use, I would be happy to update my code.

  • Because my code finds the closest FAA facility to a given waypoint, it sometimes yields the same FAA facility for 2 or more waypoints. This is especially true for flights outside of the United States.

  • I discovered turf.js (http://turfjs.org/) fairly early in the process, but didn't realize how powerful it was until later. My code could doubtless be rewritten much better with turf.js

  • I livestreamed my attempt to solve this problem and the recordings are available at: https://www.youtube.com/playlist?list=PLQiTKaefaTLpfUVJETwWX31IxLypqA7xy (videos 62-72, ie, those that mention waypoints, geography, or great circle).

I'm hesitant to post this link, because, in addition to the usual worthlessness of my videos, I spent a lot of time trying to find a closed-form formula for points along a great circle. Though I eventually succeeded, the resulting 250+ line formula is far too ugly for use.

  • would you be able to explain what happens inside waypoints(obj); ? how is it controlling the results based on NumberOfWaypoints., – HaBo Jan 14 at 10:08
  • I updated my question with code I could come up with. But the challenge is, I am not able rightly set waypoint limit. with my above code, I am getting around 225 waypoints from start to end (KBTP - KMYR). How do I limit to a given Number? – HaBo Jan 14 at 10:22
  • I think I fixed with. Now it is showing reasonable stops – HaBo Jan 14 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.