Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

When I evaluate

CityData[All, "Coordinates"]

Mathematica returns

{Missing["NotAvailable"], Missing["NotAvailable"]}

but when I evaluate CityData[All] or CityData[{All, "USA"}], it behaves as expected, and returns a gigantic list of cities.

I'm curious to modify the neat example for FindShortestTour, to use coordinates from CityData -- yes it may take a very long time, but I'm curious to see for myself :)

My guess is that it is because not every city in the database has coordinates mapped thereto - but why is Mathematica failing this way? How can I programmatically eliminate the cities with 'bad' coordinates? Or programmatically build a list of all cities that do have coordinates?

share|improve this question

2 Answers 2

up vote 10 down vote accepted

Try this:

CityData[#, "Coordinates"] & /@ CityData[All]

also if you want the city too

{#, CityData[#, "Coordinates"]} & /@ CityData[All]

I assume that the option "Coordinates" need a specific city so you have to retrieve all the available cities in the database and then feed each one to CityData to get its coordinates.

share|improve this answer
    
Awesome. Exactly what I needed. –  Alexander Riccio Apr 16 '13 at 3:45

As @Spawn1701D mentioned, you have to retrieve the data then map CityData across it. You can also just look at specific cities instead of loading every city in the world which seems like it would be unnecessary for some situations. For example to get just data about cities in New York you can do:

CityData[#, "Coordinates"] & /@ CityData[{All, "NewYork"}]

You can then try your modified FindShortestTour "neat example" on this data before extending it to much larger data.

share|improve this answer
    
Actually, although there are 100k+ entries for all the cityes I got them quite fast. –  Spawn1701D Apr 15 '13 at 5:13
    
@Spawn1701D, I was referring to the FindShortestTour example the OP is trying to modify. –  RunnyKine Apr 15 '13 at 5:49
    
I am just referring to the " instead of loading every city in the world which seems like it would take a while". I can's say anything about the FindShortestTour part. –  Spawn1701D Apr 15 '13 at 5:52
    
@Spawn1701D, yes you're right it loaded fast for me too. –  RunnyKine Apr 15 '13 at 5:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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