Let's say we want to be able to calculate the distance that an aircraft flew, and over which countries it flew.
In this example, we will go through the steps necessary to recover the data from a flight and calculate the distance flown during the flight using the Tracking History API.
First, we will look at a specific airport, from which we will single out a specific flight to analyze.
Let's take CDG airport here. We will look at this GeoJSON representing the area of the airport:
Which is represented like that on a map:
Using the coordinates previously shown, we can filter the API results for the area we want:
- Latitude range:
48.970752,49.041694need to be South to North, so values can vary from
- Longitude range:
2.481443,2.642431need to be West to East, so values can vary from
Let's breakdown what we did here:
- We queried our endpoint around CDG airport during a specific time.
- We parsed the results and generated a Pandas Dataframe from them.
- We filtered out all flights with the route LHR to CDG.
From the filtered flights fitting our requirement (LHR to CDG), we pick out the first of those and query the Tracking History endpoint again, this time removing geo limitations. For this work out, we will need to install an additional package: geopy
Let's break down what we did here:
- We selected the first flight in our filtered data
flight_analysed.iloc, and queried the Tracking History endpoint to get this specific flight using its ICAO address as the API filter.
- We generated a Panda Dataframe with the retrieved data.
- We iterate over every data point, and generated an array of coordinates, which we will use to add up the distance between every points. For that we will use the geopy package, that calculates distance between 2 sets of coordinates.
We can now make use of the reverse_geocoder package, which is an offline geocoder that will allow us to get useful information from coordinates such as the country.
Here is the expected output from our example: