Skip to main content

Tools for manipulating X-Plane's apt.dat files & interfacing with the X-Plane Scenery Gateway

Project description

xplane_airports: Tools for working with X-Plane airport data

xplane_airports is a Python package for interacting with X-Plane's airport data (apt.dat) files.

There are two primary components to this:

  1. The AptDat module: used to parse & query raw apt.dat files (e.g., the files stored on disk in your X-Plane installation)
  2. The gateway module: used to interact with the X-Plane Scenery Gateway to get information about what airports are available, and to download individual scenery packs contributed by the community.

The AptDat module

Tools for reading, inspecting, and manipulating X-Plane’s airport (apt.dat) files.

AptDat

class AptDat.AptDat(path_to_file=None)

A container class for Airport objects. Parses X-Plane’s gigantic apt.dat files, which may have data on hundreds of airports.

Field airports
Type: list[Airport]

static from_file_text(apt_dat_file_text, from_file)
Parameters:

  • apt_dat_file_text (str): The contents of an apt.dat (or ICAO.dat) file
  • from_file (str): Path to the file from which this was read

Property ids
Returns: A generator containing the X-Plane IDs of all airports in the collection. Note that these IDs may or may not correspond to the airports’ ICAO identifiers.
Return type: collection.Iterable[str]

Property names
Returns: A generator containing the names of all airports in the collection
Return type: collection.Iterable[str]

Method search_by_id(apt_id)
Parameter: apt_id (str) – The X-Plane ID of the airport you want to query
Returns: The airport with the specified ID, or None if no matching airport exists in this collection.
Return type: Union[Airport, None]

Method search_by_name(apt_name)
Parameter: apt_name (str) – The name of the airport you want to query
Returns: All airports that match the specified name, case-insensitive (an empty list if no airports match) Return type: list[Airport]

Method search_by_predicate(predicate_fn)
Parameter: predicate_fn ((Airport) -> bool) – We will collect all airports for which this function returns True
Return type: list[Airport]

Method sort(key='name')
By default, we store the airport data in whatever order we read it from the apt.dat file. When you call sort, though, we’ll ensure that it’s in order (default to name order, just like it’s always been in the shipping versions of X-Plane).
Parameter: key (str) – The Airport key to sort on

class xplane_airports.AptDat.``Airport(name: str, id: str, from_file: str = '', has_atc: bool = False, elevation_ft_amsl: float = 0, text: List[xplane_airports.AptDat.AptDatLine] = )

A single airport from an apt.dat file.

static from_lines(apt_dat_lines, from_file_name)

Parameters:

from_file_name (str) – The name of the apt.dat file you read this airport in from

Return type:

Airport

static from_str(file_text, from_file_name)

Parameters:

  • file_text (str) – The portion of the apt.dat file text that specifies this airport
  • from_file_name (str) – The name of the apt.dat file you read this airport in from

Return type:

Airport

has_comm_freq

Returns:

True if this airport defines communication radio frequencies for interacting with ATC

Return type:

bool

has_ground_routes

Returns:

True if this airport defines any destinations for ground vehicles (like baggage cars, fuel trucks, etc.), ground truck parking locations, or taxi routes

Return type:

bool

has_row_code(row_code_or_codes)

Parameters:

row_code_or_codes (Union_[int,_ str_,_ collections.Iterable_[int]__]_) – One or more “row codes” (the first token at the beginning of a line; almost always int)

Returns:

True if the airport has any lines in its text that begin with the specified row code(s)

Return type:

bool

has_taxi_route

Returns:

True if this airport defines routing rules for ATC’s use of its taxiways.

Return type:

bool

has_taxiway

Returns:

True if this airport defines any taxiway geometry

Return type:

bool

has_taxiway_sign

Returns:

True if this airport defines any taxi signs

Return type:

bool

has_traffic_flow

Returns:

True if this airport defines rules for when and under what conditions certain runways should be used by ATC

Return type:

bool

latitude

Returns:

The latitude of the airport, which X-Plane calculates as the latitude of the center of the first runway.

Return type:

float

longitude

Returns:

The longitude of the airport, which X-Plane calculates as the longitude of the center of the first runway.

Return type:

float

class xplane_airports.AptDat.``AptDatLine(line_text)

A single line from an apt.dat file.

is_airport_header()

Returns:

True if this line marks the beginning of an airport, seaport, or heliport

Return type:

bool

is_file_header()

Returns:

True if this is part of an apt.dat file header

Return type:

bool

is_ignorable()

Returns:

True if this line carries no semantic value for any airport in the apt.dat file.

Return type:

bool

is_runway()

Returns:

True if this line represents a land runway, waterway, or helipad

Return type:

bool

runway_type

Returns:

The type of runway represented by this line

Return type:

RunwayType

tokens

Returns:

The tokens in this line

Return type:

list[str]

class xplane_airports.AptDat.``RunwayType

Row codes used to identify different types of runways

The gateway module

Tools for interfacing with the X-Plane Scenery Gateway’s API (docs at: https://gateway.x-plane.com/api)

class xplane_airports.gateway.``GatewayApt(apt: xplane_airports.AptDat.Airport, txt: Optional[str], readme: str, copying: str, pack_metadata: dict, apt_metadata: Optional[dict])

All the data we get back about an airport when we download a scenery pack via scenery_pack()

class xplane_airports.gateway.``GatewayFeature

Features that may be used to tag scenery packs on the Gateway. Note that these are subject to frequent addition/removal/change; only a few are guaranteed to be stable.

xplane_airports.gateway.``airport(airport_id)

Queries the Scenery Gateway for metadata on a single airport, plus metadata on all the scenery packs uploaded for that airport. Documented at: https://gateway.x-plane.com/api#get-a-single-airport

Parameters:

airport_id (str) – The identifier of the airport on the Gateway (may or may not be an ICAO ID)

Returns:

A dict with metadata about the airport

Return type:

dict

>>> expected_keys = {'icao', 'airportName', 'airportClass', 'latitude', 'longitude', 'elevation', 'acceptedSceneryCount', 'approvedSceneryCount', 'recommendedSceneryId', 'scenery'} >>> ksea = airport('KSEA') >>> all(key in ksea for key in expected_keys) True

Includes metadata of all scenery packs uploaded for this airport:

>>> len(airport('KSEA')['scenery']) >= 9 True

>>> all_scenery_metadata = airport('KSEA')['scenery'] >>> first_scenery_pack_metadata = all_scenery_metadata[0] >>> expected_keys = {'sceneryId', 'parentId', 'userId', 'userName', 'dateUploaded', 'dateAccepted', 'dateApproved', 'dateDeclined', 'type', 'features', 'artistComments', 'moderatorComments', 'Status'} >>> all(key in first_scenery_pack_metadata for key in expected_keys) True

xplane_airports.gateway.``airports()

Queries the Scenery Gateway for all the airports it knows about. Note that the download size is greater than 1 MB. Documented at: https://gateway.x-plane.com/api#get-all-airports

Returns:

A dict with metadata on all 35,000+ airports; keys are X-Plane identifiers (which may or may not correspond to ICAO identifiers), and values are various airport metadata.

Return type:

dict

>>> airports()['KSEA'] {'AirportCode': 'KSEA', 'AirportName': 'Seattle Tacoma Intl', 'AirportClass': None, 'Latitude': 47, 'Longitude': -122, 'Elevation': None, 'Deprecated': None, 'DeprecatedInFavorOf': None, 'AcceptedSceneryCount': 2, 'ApprovedSceneryCount': 2, 'ExcludeSubmissions': 0, 'RecommendedSceneryId': 45283, 'Status': 'Scenery Submitted', 'SceneryType': 0, 'SubmissionCount': 2}

>>> len(airports()) > 35000 True

xplane_airports.gateway.``recommended_scenery_packs(selective_apt_ids=None)

A generator to iterate over the recommended scenery packs for all (or just the selected) airports on the Gateway. Downloads and unzips all files into memory.

Parameters:

selective_apt_ids (Union_[collections.Iterable[str]_,_ None]_) – If None, we will download scenery for all 35,000+ airports; if a list of airport IDs (as returned by airports()), the airports whose recommended packs we should download.

Returns:

A generator of the recommended scenery packs; each pack contains the same data as a call to scenery_pack() directly

Return type:

collections.Iterable[GatewayApt]

Easily request a subset of airports:

>>> packs = recommended_scenery_packs(['KSEA', 'KLAX', 'KBOS']) >>> len(list(packs)) == 3 and all(isinstance(pack, GatewayApt) for pack in packs) True

Audit airports for specific features:

>>> all_3d = True >>> all_have_atc_flow = True >>> all_have_taxi_route = True >>> for pack in recommended_scenery_packs(['KATL', 'KORD', 'KDFW', 'KLAX']): ... all_3d &= pack.pack_metadata['type'] == '3D' and pack.txt is not None ... all_have_atc_flow &= GatewayFeature.HasATCFlow in pack.pack_metadata['features'] and pack.apt.has_traffic_flow() ... all_have_taxi_route &= GatewayFeature.HasTaxiRoute in pack.pack_metadata['features'] and pack.apt.has_taxi_route() >>> all_3d and all_have_atc_flow and all_have_taxi_route True

xplane_airports.gateway.``scenery_pack(pack_to_download)

Downloads a single scenery pack, including its apt.dat and any associated DSF from the Gateway, and unzips it into memory.

Parameters:

pack_to_download (Union_[str,_ int_]_) – If int, the scenery ID of the pack to be downloaded; if str, the airport whose recommended pack we should download.

Returns:

the downloaded files and the metadata about the scenery pack

Return type:

GatewayApt

>>> expected_keys = {'sceneryId', 'parentId', 'icao', 'aptName', 'userId', 'userName', 'dateUploaded', 'dateAccepted', 'dateApproved', 'dateDeclined', 'type', 'features', 'artistComments', 'moderatorComments', 'additionalMetadata', 'masterZipBlob'} >>> ksea_pack_metadata = scenery_pack('KSEA').pack_metadata >>> all(key in ksea_pack_metadata for key in expected_keys) True >>> scenery_pack('KORD').pack_metadata['type'] in ('3D', '2D') True >>> all(isinstance(feature, GatewayFeature) for feature in scenery_pack('KMCI').pack_metadata['features']) True

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xplane_airports-1.0.0.tar.gz (17.4 kB view hashes)

Uploaded Source

Built Distribution

xplane_airports-1.0.0-py3-none-any.whl (16.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page