4
$\begingroup$

I have a list of airport codes:

airports = {"ABE", "ABI", "ACT"}

How can I convert this into a list of entities in Mathematica? Is this possible? I tried:

Entity["Airport"] /@ airports

but this does not give a correct result.

Thank you for your help! In the end, I need various properties like city, longitude and latitude from those airports.

Any ideas? Help is appreciated!

Regards, Sebastian

$\endgroup$

2 Answers 2

4
$\begingroup$

You're pretty close. The following code should do it:

Entity["Airport", #]& /@ airports
$\endgroup$
2
  • $\begingroup$ Awesome! Thank you! $\endgroup$
    – STATWORX
    Commented Jun 11, 2015 at 18:57
  • 1
    $\begingroup$ also Interpreter["Airport"][airports] $\endgroup$
    – chuy
    Commented Jun 11, 2015 at 19:07
5
$\begingroup$
airports = {"ABE", "ABI", "ACT"};

AirportData["Properties"]

enter image description here

data = AirportData[#, {"IATACode", "Name", "Cities", "Latitude", 
      "Longitude"}] & /@ airports;

data // Grid

enter image description here

airports = {"ABE", "ABI", "ACT"};

EDIT: A quicker method would be to download a .csv file and filter it.

data = Import["http://ourairports.com/data/airports.csv"];

The data elements in the file are

data[[1]]

{"id", "ident", "type", "name", "latitude_deg", "longitude_deg", "elevation_ft", "continent", "iso_country", "iso_region", "municipality", "scheduled_service", "gps_code", "iata_code", "local_code", "home_link", "wikipedia_link", "keywords"}

Selecting the data elements of interest

data2 = data[[All, {14, 4, 11, 10, 5, 6}]];

Selecting the airports of interest

Select[data2, MemberQ[airports, #[[1]]] &] // Grid

enter image description here

$\endgroup$
3
  • $\begingroup$ Great, this is what I am looking for. There remains one issue: my list of airport codes contains 270 elements, which runs super slow. I believe that this is related to the use of entity objects which were introduced in 10.0. Any ideas on that issue? How can I speed up the lookup of properties for many airports? Thank you all, I appreciate your help. $\endgroup$
    – STATWORX
    Commented Jun 13, 2015 at 17:47
  • $\begingroup$ See edit above using .csv file. $\endgroup$
    – Bob Hanlon
    Commented Jun 14, 2015 at 14:53
  • $\begingroup$ nice! thank you! $\endgroup$
    – STATWORX
    Commented Jun 15, 2015 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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