Function Repository Resource:

GeoSpatialDistanceList

Source Notebook

Get a list of spatial distances between consecutive pairs of locations

Contributed by: Peter Cullen Burbery

ResourceFunction["GeoSpatialDistanceList"][{loc1,loc2,}]

returns the list of successive spatial distances between consecutive pairs of locations.

Details

The spatial distance is the straight-line distance between two points on Earth, or the distance travelled if one could tunnel through the Earth from one point to the other.
The distances are returned in the unit system specified by $UnitSystem.

Examples

Basic Examples (2) 

Find the successive distances between your location, Null Island, which is the area of ocean near Africa with 0 latitude and 0 longitude, the North and South Poles, and the antipode of your location:

In[1]:=
ResourceFunction[
 "GeoSpatialDistanceList"][{Here, GeoPosition["NullIsland"], GeoPosition["NorthPole"], GeoPosition["SouthPole"], GeoAntipode[Here]}]
Out[1]=

Convert to kilometers:

In[2]:=
UnitConvert[%, "SI"]
Out[2]=

Applications (13) 

A megacity, according to the United Nations Department of Economic and Social Affairs, is an urban agglomeration with 10 million inhabitants. Compute the positions for a list of megacities:

In[3]:=
megacities = {Entity["City", {"Tokyo", "Tokyo", "Japan"}], Entity["City", {"Delhi", "Delhi", "India"}], Entity["City", {"Shanghai", "Shanghai", "China"}], Entity["City", {"SaoPaulo", "SaoPaulo", "Brazil"}], Entity["City", {"MexicoCity", "DistritoFederal", "Mexico"}], Entity["City", {"Cairo", "Cairo", "Egypt"}], Entity["City", {"Osaka", "Osaka", "Japan"}], Entity["City", {"NewYork", "NewYork", "UnitedStates"}], Entity["City", {"Karachi", "Sind", "Pakistan"}], Entity["City", {"BuenosAires", "BuenosAires", "Argentina"}], Entity["City", {"Chongqing", "Chongqing", "China"}], Entity["City", {"Istanbul", "Istanbul", "Turkey"}], Entity["City", {"Calcutta", "WestBengal", "India"}], Entity["City", {"Lagos", "Lagos", "Nigeria"}], Entity["City", {"RioDeJaneiro", "RioDeJaneiro", "Brazil"}], Entity["City", {"Tianjin", "Tianjin", "China"}], Entity["City", {"Kinshasa", "Kinshasa", "DemocraticRepublicCongo"}], Entity["City", {"Guangzhou", "Guangdong", "China"}], Entity["City", {"LosAngeles", "California", "UnitedStates"}], Entity["City", {"Moscow", "Moscow", "Russia"}], Entity["City", {"Shenzhen", "Guangdong", "China"}], Entity["City", {"Lahore", "Punjab", "Pakistan"}], Entity["City", {"Bengaluru", "Karnataka", "India"}], Entity["City", {"Paris", "IleDeFrance", "France"}], Entity["City", {"Bogota", "DistritoCapital", "Colombia"}], Entity["City", {"Jakarta", "Jakarta", "Indonesia"}], Entity["City", {"Madras", "TamilNadu", "India"}], Entity["City", {"Lima", "Lima", "Peru"}], Entity["City", {"Bangkok", "Bangkok", "Thailand"}]};
In[4]:=
positions = Thread[GeoPosition[megacities]]
Out[4]=

Find the successive spatial distances for a list of megacities:

In[5]:=
UnitConvert[
 ResourceFunction["GeoSpatialDistanceList"][positions], "SI"]
Out[5]=

Compare with the result of GeoDistanceList:

In[6]:=
Normal[UnitConvert[GeoDistanceList[positions], "SI"]]
Out[6]=

Find the difference:

In[7]:=
UnitConvert[ResourceFunction["GeoSpatialDistanceList"][positions], "SI"] - Normal[UnitConvert[GeoDistanceList[positions], "SI"]]
Out[7]=

Find the average decrease in distance if you could travel through the Earth:

In[8]:=
Mean[UnitConvert[
   ResourceFunction["GeoSpatialDistanceList"][positions], "SI"] - Normal[UnitConvert[GeoDistanceList[positions], "SI"]]]
Out[8]=

Find how fast it would take to travel this distance at the speed of light:

In[9]:=
UnitSimplify[
 Mean[UnitConvert[
     ResourceFunction["GeoSpatialDistanceList"][positions], "SI"] - Normal[UnitConvert[GeoDistanceList[positions], "SI"]]]/
  Quantity["SpeedOfLight"]]
Out[9]=

Find the shortest path starting and ending at the two closest megacities to your location:

In[10]:=
{startcity, destinationcity} = First[GeoNearest["City", #]]["Name"] & /@ TakeSmallestBy[positions, GeoDistance[#, Here] &, 2]
Out[10]=

Find the index of the cities:

In[11]:=
{startcityindex, endcityindex} = Flatten[Position[megacities, #] & /@ {startcity, destinationcity}]
Out[11]=

Find the shortest tour of all mega-cities:

In[12]:=
shortesttourorder = Last[FindShortestTour[positions, 8, 5]]
Out[12]=

Compare the distances with GeoDistance over Earth's surface and GeoSpatialDistance through space:

In[13]:=
geodesicdistance = First[FindShortestTour[positions, 8, 5]]
Out[13]=
In[14]:=
spatialdistance = Quantity[
  First[FindShortestTour[positions, 8, 5, DistanceFunction -> (QuantityMagnitude[
        ResourceFunction["GeoSpatialDistance"][#1, #2]] &)]], "Kilometers"]
Out[14]=

Find the difference:

In[15]:=
Abs[geodesicdistance - spatialdistance]
Out[15]=

Evaluate how fast this would take to travel at the speed of light:

In[16]:=
UnitSimplify[
 Abs[geodesicdistance - spatialdistance]/Quantity["SpeedOfLight"]]
Out[16]=

Make a map of the cities with geo markers for each city:

In[17]:=
GeoGraphics[{{Thick, Red, GeoPath[positions[[{
Quantity[61590.728145031404`, "Kilometers"], {8, 25, 28, 10, 4, 15, 14, 17, 6, 12, 24, 20, 22, 2, 9, 23, 27, 13, 29, 26, 21, 18, 11, 16, 3, 7, 1, 19, 5}}[[2]]]]]}, GeoMarker[positions, "Scale" -> 4]}, GeoBackground -> "VectorBusiness"]
Out[17]=

Publisher

Peter Burbery

Version History

  • 1.0.0 – 22 August 2022

Related Resources

License Information