13
$\begingroup$

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]

enter image description here

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?

$\endgroup$
6
  • 2
    $\begingroup$ 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. $\endgroup$ – C. E. Sep 10 '14 at 13:47
  • $\begingroup$ @Pickett or simply start on a new line with "=" :D $\endgroup$ – Yves Klett Sep 10 '14 at 13:48
  • 1
    $\begingroup$ @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! $\endgroup$ – C. E. Sep 10 '14 at 13:49
  • 2
    $\begingroup$ 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. $\endgroup$ – David Richerby Sep 10 '14 at 20:22
  • $\begingroup$ Many thanks @ David Richerby for the great links :) $\endgroup$ – eldo Sep 10 '14 at 21:08
13
$\begingroup$

Use Interpreter without federal state or country.

Works even for small german towns :)

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

enter image description here

EDIT:

Also you could ask for the airport:

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

enter image description here

or just use the nearest airport

GeoNearest["Airport", town]
$\endgroup$
0
12
$\begingroup$

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):

Mathematica graphics

or like this (although it misses Van Nuys):

Mathematica graphics

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

Thanks to your nice answers and comments I found a solution to my problem:

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"]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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