# Flying to Australia

I want to compare different flight routes to Australia and their lengths. So far I have written:

departure =
Entity["City", {"BuenosAires", "BuenosAires", "Argentina"}];

destination =
Entity["City", {"Perth", "WesternAustralia", "Australia"}];

km =
ToString@QuantityMagnitude@Round@(GeoDistance[departure, destination]) <> " km";

GeoGraphics[
{
{Thick, Red, GeoPath[{departure, destination}]},
Style[Text[km, GeoPosition[destination]], Blue, 14, Bold]
},
GeoCenter -> destination,
GeoProjection -> "Mercator",
GeoRange -> "World",
ImageSize -> 400,
Frame -> True]


My problem: To specify a city with Mathematica I have to include its federal state / administrative division, which, in many cases, I don' t know. So I have to google and manually input it. Since I want to automate the program for other cities the question is:

How can I persuade Mathematica to tell me that Perth, Australia, is part of Western Australia and use this answer as automated input?

• Use free-form input (you find it under the menu "Insert") as in Yves' answer with the query "Perth, Australia" and then use InputForm on the result. – C. E. Sep 10 '14 at 13:47
• @Pickett or simply start on a new line with "=" :D – Yves Klett Sep 10 '14 at 13:48
• @YvesKlett I use the keyboard shortcut, but I think it varies between operating systems so I thought it was safer to indicate where to locate it. With = you can't append // InputForm so it becomes a two-step process! – C. E. Sep 10 '14 at 13:49
• If what you actually want is the answer, rather than the way to compute it with Mathematica, the Great Circle Mapper does the job well. For example, Perth to Buenos Aires. In either case, be aware that an actual flight from Perth to Buenos Aires would not take the indicated route directly over the south pole because that would leave it without any possibility of diversions if something went wrong. Ask on Travel or Aviation for more information on that kind of thing. – David Richerby Sep 10 '14 at 20:22
• Many thanks @ David Richerby for the great links :) – eldo Sep 10 '14 at 21:08

Use Interpreter without federal state or country.

Works even for small german towns :)

Interpreter["City"]["Memmingen"]
GeoPosition[%]
GeoGraphics[%]


EDIT:

Also you could ask for the airport:

town = Interpreter["City"]["Memmingen"];
airport = Interpreter["Airport"]["Memmingen"];
GeoPosition[{town, airport}]


or just use the nearest airport

GeoNearest["Airport", town]


You could use the official ICAO abbreviation:

Entity["Airport", "KLAX"]

which makes sense because you will only be able to use officially named airports most of the time anyway.

You can always get those (or the city details) via a W|A query and work your way from there (no googling involved):

or like this (although it misses Van Nuys):

• Thanks @ Yves - this really helps and is much shorter and clearer :) – eldo Sep 10 '14 at 13:42
• you could use "Interpreter["City"]["Perth"]", too – Phab Sep 10 '14 at 13:54
• @Phab even though your suggestion killed my kernel the first time around, please add this as another answer ;-) – Yves Klett Sep 10 '14 at 13:57
• @Phab I fully agree with Yves Klett, especially if you would append InputForm :) – eldo Sep 10 '14 at 13:59
• even better - search for the nearest airport: GeoNearest["Airport", yourTown] – Phab Sep 10 '14 at 14:10

FlightPath[cities_List, pro_: "AzimuthalEquidistant"] :=

Module[{lc = Length@cities, color, dest, dist, entity, legend, pair, path},

color = {Red, Darker@Green, Blue, Black, Orange, Purple};
entity = Interpreter["City"][#] & /@ cities;
dest = GeoPosition@First@entity;
pair = Map[{entity[[#]], entity[[1]]} &, Range[2, lc]];
path = Transpose[{Take[color, lc - 1], GeoPath /@ pair}];
dist = Map[# <> " km" &, ToString /@ QuantityMagnitude@Round@(GeoDistance @@@ pair)];
legend = Table[(Rest@cities)[[n]] <> " " <> dist[[n]], {n, 1, lc - 1}];

Legended[
GeoGraphics[
{Thick, Sphere[dest, 0.1], path},
GeoCenter -> dest,
GeoProjection -> pro,
GeoRange -> "World",
ImageSize -> 400,
Frame -> True],
Placed[LineLegend[color, legend], After]]]


It works for up to 6 departure cities. The first city in the list is the destination.

FlightPath[{"Perth", "BuenosAires", "Berlin", "NewYork", "Lagos"}, "Mercator"]