Wolfram Language

Geo Computation

The Fastest Way to the Coast

Find out the shortest possible path to get to a point of the US border from each capital of the conterminous US states.

Take the list of capitals.

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

Take the polygon of the US.

In[2]:=
Click for copyable input
us = EntityValue[Entity["Country", "UnitedStates"], "Polygon"]
Out[2]=

Compute the closest point of the polygon boundary for each respective state capital.

In[3]:=
Click for copyable input
borderpoints = Flatten[Nearest[First[us], GeoPosition[capitals]]]
Out[3]=

Draw all the geodesic paths.

In[4]:=
Click for copyable input
GeoGraphics[{us, Point[capitals], Red, Arrowheads[0.015], Arrow /@ GeoPath /@ Thread[{capitals, borderpoints}]}]
Out[4]=

Related Examples

de es fr ja ko pt-br ru zh