Skip to content

Support parsing .kml files from ADSBExchange#2

Open
stbentia wants to merge 1 commit intodscpsyl:mainfrom
stbentia:patch-1
Open

Support parsing .kml files from ADSBExchange#2
stbentia wants to merge 1 commit intodscpsyl:mainfrom
stbentia:patch-1

Conversation

@stbentia
Copy link

ADSBExchange exported .kml files have two idiosyncrasies that require minor adjustments so FlightawareToForeflight will create valid ForeFlight G1000 files from ADSBExchange exports.

  1. ADSBExchange lat/long have 6 decimal places but ForeFlight will not process files with more than 4 decimal places. 2) ADSBExchange time stamps have fractional seconds. The prior kml2g1000.py would crash with fractional seconds in input data. Also, the time that is exported time needs to not have fractional seconds for ForeFlight to be able to import the data properly.

Note that currently option 2. "Find files directly on flightaware.com and option" 3. "Input a URL" fail to properly download and parse data from FlightAware.com. Although these changes do not attempt to fix those issues, they should not harm it either. Instead, with the code changes, one can use the Export KML feature on ADSBExchange to obtain similar results.

ADSBExchange exported .kml files have two idiosyncrasies that require minor adjustments so FlightawareToForeflight will create valid ForeFlight G1000 files from ADSBExchange exports.  

1) ADSBExchange lat/long have 6 decimal places but ForeFlight will not process files with more than 4 decimal places.  
2) ADSBExchange time stamps have fractional seconds. The prior kml2g1000.py would crash with fractional seconds in input data.  Also, the time that is exported time needs to not have fractional seconds for ForeFlight to be able to import the data properly. 

Note that currently option 2. "Find files directly on flightaware.com and option" 3. "Input a URL" fail to properly download and parse data from FlightAware.com.  Although these changes do not attempt to fix those issues, they should not harm it either.  Instead, with the code changes, one can use the Export KML feature on ADSBExchange to obtain similar results.
@stbentia
Copy link
Author

Also, the groundspeed calculation is not accurate. It can be off by 35% or more especially if going east/west for calculations further from the equator.

math.hypot(*[b - a for a, b in zip(fm, to)]) * 60.0 # nautical miles <-- this is not a good approximation because the distance of 1 degree of longitude shrinks as you move away from the equator toward the poles.

Much better would be to use the Haversine formula:

def haversine_nm(lat1, lon1, lat2, lon2):
    R_nm = 3440.065  # Earth radius in nautical miles

    lat1, lon1, lat2, lon2 = map(radians, [lat1, lon1, lat2, lon2])
    dlat = lat2 - lat1
    dlon = lon2 - lon1

    a = sin(dlat/2)**2 + cos(lat1)*cos(lat2)*sin(dlon/2)**2
    c = 2 * atan2(sqrt(a), sqrt(1 - a))

    return R_nm * c
    

Or scale longitude delta as a function of latitude, such as:


def calcNauticalMiles(fm, to):
    lat_rad = math.radians((fm[0] + to[0])/2.0)
    d_lat = to[0] - fm[0]
    d_lon = (to[1] - fm[1]) * math.cos(lat_rad) # Scale longitude
    return math.hypot(d_lat, d_lon) * 60.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant