1
$\begingroup$

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.

$\endgroup$

2 Answers 2

6
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ This is using GeoDistance and I'm looking for TravelDistance. Does that matter? $\endgroup$ Aug 15, 2020 at 17:20
  • $\begingroup$ Thank you. Some terms like allCitiesGeoGraphics don't seem to have definitions. $\endgroup$ Aug 15, 2020 at 23:01
  • $\begingroup$ @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. $\endgroup$ Aug 16, 2020 at 19:17
3
$\begingroup$

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

enter image description here

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

enter image description here

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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