# Why is CityData[All, “Coordinates”] failing?

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?

-

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.

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

-
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