Message Boards Message Boards

Do All Roads Lead to Rome? The Answer is Surprisingly Beautiful

Do All Roads Lead to Rome? The Answer is Surprisingly Beautiful by Gabrielle Bruney, is an interesting post that was recently published in theCreatorsproject blog. It shows the results of Moovel Lab's team (Benedikt Groß, Raphael Reimman and Philipp Schmitt), that visually proof the old saying that “all roads lead to Rome”. But Do All Roads Lead to Rome? The answer using the Wolfram Language and its newly built-in TravelDirections is surprisingly beautiful:

Roads to Rome

roadsToRome=ParallelMap[TravelDirections[{Entity["City",#],Entity["City", List["Rome", "Lazio", "Italy"]]},"TravelPath"]&,Flatten[CountryData["Europe","LargestCities"][[All,2]],1]];
roads=Select[roadsToRome,Head[#]==GeoPath&];
map=GeoGraphics[{GeoStyling[White],
EdgeForm[White],Polygon[EntityClass["Country", "Europe"]],
EdgeForm[],Polygon[EntityClass["Country", "Europe"]],Red,Opacity[.1],roads},GeoBackground->GeoStyling[LightBlue],GeoProjection->"Mercator",GeoRange->{{34.63,65.27},{-24.53,40.222}},ImageSize->1000];
Export["AllRoads2Rome.png",map]

Notice that I mapped over 30,000 large cities across Europe and the resulting GeoPath from each to Italy’s capital.

To generalize this to the whole World, just bear in mind that there are 10 cities called Rome in the US alone:

CityData["Rome"]

{ Entity["City",List["Rome","Lazio","Italy"]], Entity["City",List["Rome","Georgia","UnitedStates"]], Entity["City",List["Rome","NewYork","UnitedStates"]], Entity["City",List["Rome","Wisconsin","UnitedStates"]], Entity["City",List["Rome","Illinois","UnitedStates"]], Entity["City",List["Rome","Maine","UnitedStates"]], Entity["City",List["RomeJefferson","Wisconsin","UnitedStates"]], Entity["City",List["Rome","Pennsylvania","UnitedStates"]], Entity["City",List["Rome","Iowa","UnitedStates"]], Entity["City",List["Rome","Ohio","UnitedStates"]] }

GeoGraphics[{Red, PointSize[Large], Point[Drop[CityData["Rome"], 1]]}, GeoProjection -> "Mercator"]

Romes

Enjoy!

POSTED BY: Bernat Espigulé
13 Replies

enter image description here - another post of yours has been selected for the Staff Picks group, congratulations !

We are happy to see you at the top of the "Featured Contributor" board. Thank you for your wonderful contributions, and please keep them coming!

POSTED BY: Moderation Team

Hi again,

one of the little problems when you want to do these travel directions within cities is that the documentation only shows how to calculate TravelDirections between cities and/or landmark buildings.museums etc. For house to house (or street to street) directions you need the exact geolocations of the start and endpoint.

This little function might come in handy:

location[str_String] :=
GeoPosition@(ToExpression[{StringSplit[#, {"<lat>", "</lat>"}][[2]], StringSplit[#, {"<lng>", "</lng>"}][[2]]}] & @
    StringJoin@Flatten@Import["https://maps.googleapis.com/maps/api/geocode/xml?address=" <> StringReplace[str, " " -> "+"]]) 

With it you can enter two addresses as strings like so:

loc1 = location["21 Union Street Aberdeen UK"]; 
loc2 = location["University of Aberdeen UK"];

Then you can -as always- use:

TravelDirections[{loc1, loc2}]["Dataset"]

to get:

enter image description here

Or else:

TravelDirections[{loc1, loc2}]["TravelDistance"]
(*Quantity[1.98282, "Miles"]*)

Cheers,

Marco

POSTED BY: Marco Thiel

That's very handy indeed. Marco, thanks for sharing it!

POSTED BY: Bernat Espigulé
POSTED BY: Marco Thiel
POSTED BY: Sander Huisman
POSTED BY: Marco Thiel

You might have to use a fast equivalent of GeoDistance, as the earth is curved rather than flat: Norm[{lat1,lon1}-{lat2,lon2}] probably won't give nice results. I'm not sure how to do Voronoi tesselations (quickly) with different norms (Manhattan norm for example).

POSTED BY: Sander Huisman

Hi Marco, I'm really sorry to hear that. I should have warn you about the difficulty of rendering 3.96GB of travel directions data in a single GeoGraphics. My suggestion is to decrease the resolution of the GeoPaths. Here is a simple example that tries to find all the travel directions to Rome from all the other capitals of the World. 131 out of 239 capital cities can be reached by car from Rome, being Singapore the capital that takes the longest to reach ( 671220 seconds, almost 8 days driving straight ).

directions=TravelDirections[{CountryData[#,"CapitalCity"],Entity["City",{"Rome","Lazio","Italy"}]}]&/@DeleteCases[CountryData[],Entity["Country","Italy"]];
directions = DeleteCases[directions, _Symbol];
(* Merge the GeoPaths, decrease the resolution by taking a point every 500 points, and color the paths with VertexColors normalized according to the longest travel time: 671220 seconds *)
paths=GeoPath[GeoPosition[pts=Take[Flatten[#["TravelPath"][[1,1]],1],{1,-1,500}]],VertexColors->Table[ColorData["Rainbow"][QuantityMagnitude[#["TravelTime"],"Seconds"]/671220-i/Length[pts]],{i,Length[pts]}]]&/@directions;
(* Render the colored geopaths in GeoGraphics *)
GeoGraphics[{Inset[BarLegend[{"Rainbow",{0,8}},LegendLayout->"Row",LegendLabel->Style["Days",Black,Bold,12],LegendMarkerSize->300],GeoPosition[{-11.45,77.13}]],Thickness[.003],paths,Red,PointSize[.008],Point[Entity["City",{"Rome","Lazio","Italy"}]]},GeoProjection->"Mercator",GeoBackground->GeoStyling["StreetMapNoLabels"],ImageSize->1000]

All capitals to Rome

Attached is the notebook with the colored paths exported as an m file.

Attachments:
POSTED BY: Bernat Espigulé

Very nice! To speed up the visualisation you can use the travelpath option:

pts=CirclePoints[{45.0,5.0},3,10000];
AbsoluteTiming[GeoGraphics[GeoPath[pts,"TravelPath"]]]
AbsoluteTiming[GeoGraphics[GeoPath[pts]]]

roughly 90x faster!

POSTED BY: Sander Huisman

Great tip, thanks!

POSTED BY: Bernat Espigulé

I'm not sure what the difference is, but I think it just draws straight lines rather then curves (Geodesic). So you can just as well use:

GeoPath[pts,"TravelPath"]
Line[Reverse/@pts]

look the same to me...

POSTED BY: Sander Huisman

Wow! Nicely done using Opacity!! I just made a very similar post here! I was curious about the roads to the city I live in. I really wanted to change the thickness, so it took some more lines of code...

POSTED BY: Sander Huisman

Sander, that's really well-executed! Benoit Mandelbrot would be happy to see that not only nature but human-made roads can generate beautiful fractals.

POSTED BY: Bernat Espigulé
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract