# How to compute a list of cities within a given radius of another city?

I have hitherto found a solution to this problem.

Designate a city in the continental USA as cityCenter.

Make a table with all large cities in the USA. I could also just try for large cities.

Of those cities in the list, the list includes data from the continental USA.

Use a module to list all cities which match the following criteria; distance between cityCenter and that city is at most a fixed radius. If the distance is less than a fixed real number, add to final list.

Example: From San Francisco, some cities as far as Sacramento appear but not for Florida.

Any insights would be appreciated.

This sort of thing is really easy to do in Mathematica:

allCities = CountryData["UnitedStates", "LargestCities"];
cityCenter = Entity["City", {"SanFrancisco", "California", "UnitedStates"}];
Select[allCities, GeoDistance[#, cityCenter] < Quantity[500, "Kilometers"] &]


{San Jose, San Francisco, Fresno, Sacramento, Oakland, Bakersfield, Stockton, Reno, Fremont}

The first time you run this, it might take some time while it downloads all required data.

To input a city into a notebook, press Ctrl+= to bring up a free-form input field. You can type the name of the city in there and Mathematica will try to find the city you meant. That's how I produced Entity["City", {"SanFrancisco", "California", "UnitedStates"}] in this example.

• This is using GeoDistance and I'm looking for TravelDistance. Does that matter? Commented Aug 15, 2020 at 17:20
• Thank you. Some terms like allCitiesGeoGraphics don't seem to have definitions. Commented Aug 15, 2020 at 23:01
• @VeritasLux Yes, you can use TravelDistance as well. You just need to use TravelDistance[{#, cityCenter}] instead of GeoDistance[#, cityCenter] (note the curly brackets). It will also be a lot slower than GeoDistance. Commented Aug 16, 2020 at 19:17

Using allCities and cityCenter from Sjoerd's answer, we can also use GeoWithinQ and GeoDisk as follows:

geodisk = GeoDisk[cityCenter, Quantity[500, "Kilometers"]];

selected = Select[GeoWithinQ[geodisk]] @ allCities


GeoGraphics[{geodisk, Red, Point@ GeoPosition @ selected,
PointSize[Large], Blue, Point @ GeoPosition @ cityCenter}]


See also this closely related Q/A: Using Geo commands, how do I get a list of cities that all meet the following criteria