Message Boards Message Boards

Get "Shortest City Tours" on Australia?

Posted 7 years ago

I was trying this guide on Australia: http://www.wolfram.com/programming-lab/explorations/shortest-city-tours/

I did:

coords = EntityValue[GeoEntities[Entity["Country", "Australia"], "City"], "Coordinates"]
route = Last[FindShortestTour[coords]]
GeoGraphics[{Thick, Red, Line[coords[[route]]]}]

The result is in the attachment. As you can see, it's above the map. What did I do wrong?

Attachments:
POSTED BY: L J
6 Replies
Posted 7 years ago

Thanks guys! Changing it from Line to GeoPath works. As suggested, I reported it to Wolfram a few days ago, so hopefully it'll be fixed soon. Thanks again :)

POSTED BY: L J

Note that this is not a bug. It should be like you described in your original post. Coordinates are in the x,y form while GeoGraphics accepts Lat,Lon pairs ('y','x').

Using Position with entityValue gives coordinates in the lat,lon format.

POSTED BY: Sander Huisman

Sander,

You are correct. The bug I was referring to was not in Mathematica but a bug in the wolfram website example. The code as posted has the error because it tries to use line on Lat,Lon pairs.

POSTED BY: Neil Singer

The underlying reason is that Line accepts x,y coordinates, while GeoPath accepts latitude longitude pairs (which is kinda y,x). Can indeed be solved in many ways:

coords = EntityValue[GeoEntities[Entity["Country", "Australia"], "City"], "Coordinates"];
route = Last[FindShortestTour[coords]];
GeoGraphics[{Thick, Red, Line[Reverse /@ coords[[route]]]}]
GeoGraphics[{Thick, Red, Line[coords[[route, {2, 1}]]]}]
GeoGraphics[{Thick, Red, GeoPath[coords[[route]]]}]
POSTED BY: Sander Huisman

Line can work too... if in the original 1st line "Coordinates" are replaced with "Position":

coords = EntityValue[GeoEntities[Entity["Country", "Australia"], "City"], "Position"]

LJ you should carefully examine the outputs your code produces and you would be able to figure out the issue. Something changed in syntax but there are still a work around so you can go further with your studies.

Cheers!

POSTED BY: Sam Carrettie

There is a bug in the example. Please report this to Wolfram so they can fix the website.

Should be GeoPath instead of Line.

GeoGraphics[{Thick, Red, GeoPath[coords[[route]]]}]

to get:

enter image description here

POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract