Message Boards Message Boards

1
|
1987 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:
GROUPS:

Finding the shortest tour around the world using Capitals instead of center

Posted 9 years ago
Attachments:
POSTED BY: Daniel C.
2 Replies

Type Ctrl + = and then type "Capital of Japan". Mathematica will convert this into code for you. The result is:

CountryData["Japan", "CapitalCity"]

This is how you access the capital of a city. The predictive Interface (the bar below the results) will have a button for "Coordinates". This shows you how to get the coordinates:

CityData["Tokyo", "Coordinates"]

Putting these together you get:

CityData[CountryData["Japan", "CapitalCity"], "Coordinates"]

You can use this in your code instead of (CountryData[#, "CenterCoordinates"] &)

Some of the data is missing for various reasons. Maybe a country doesn't have a defined capital for some reason. You'll need to remove the missing cases. Overall, you want to redefined centers as:

centers = 
 DeleteCases[
  Map[CityData[CountryData[#, "CapitalCity"], "Coordinates"] &, 
    places] /. GeoPosition -> Identity, {Missing["NotAvailable"], 
   Missing["NotAvailable"]}]

You'll probably want to rename "centers" to something like "capitals" in the code as well.

POSTED BY: Sean Clarke
Posted 9 years ago

Thank you very much!

POSTED BY: Daniel C.
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