Message Boards Message Boards

1
|
2246 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 10 years ago

Hello,

I'm interested in trying to find the shortest tour around the world. I saw this sample given by Wolfram (attached) to accomplish this, but it uses the centers of countries instead of the capitals. Is there anyway to use CountryData or AdministrativeDivisionData to enable the script to use capitals?

If not, would it be possible for WA to add coordinates for country capitals to CountryData?

Thanks, Dan C.

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 10 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