Wolfram Language

Geo Computation

Travel All Capitals of the Conterminous US States

Obtain the list of the capitals of the 48 conterminous US states.

In[1]:=
Click for copyable input
capitals = EntityValue[ EntityClass["AdministrativeDivision", "ContinentalUSStates"], "CapitalCity"]
Out[1]=

Download their GeoPosition coordinates.

In[2]:=
Click for copyable input
GeoPosition[capitals]
Out[2]=

Compute the order in which the cities should be visited to minimize the total geodetic distance.

In[3]:=
Click for copyable input
GeoPosition[capitals]; {d, perm} = FindShortestTour[%]
Out[3]=

Represent that path on a map.

In[4]:=
Click for copyable input
GeoGraphics[{GeoPath[capitals[[perm]]], Red, PointSize[Medium], Point[capitals]}]
Out[4]=

Now compute travel directions to drive through the same cities in the same order.

In[5]:=
Click for copyable input
td = TravelDirections[capitals[[perm]]];

Represent the corresponding path on a map.

In[6]:=
Click for copyable input
GeoGraphics[{td["TravelPath"], Red, PointSize[Medium], Point[capitals]}]
Out[6]=

The total distance to drive is shown.

In[7]:=
Click for copyable input
td["TravelDistance"]
Out[7]=

Compare with the geodetic distance.

In[8]:=
Click for copyable input
d
Out[8]=

Related Examples

de es fr ja ko pt-br ru zh