3
$\begingroup$

How can I generate a Geo plot similar to the Wiki page about left- and right-handed traffic.

Question

A direct way would be to make a list of countries that follow L/R traffic handedness and plot. I was wondering if there a way to get this information from the Entity system?

enter image description here

Attribution (link doesn't work): By Benjamin D. Esham (bdesham) - This W3C-unspecified vector image was created with Inkscape ., Public Domain, https://commons.wikimedia.org/w/index.php?curid=2653447

$\endgroup$
1
  • 2
    $\begingroup$ Download the .csv file from here and import it $\endgroup$
    – Bob Hanlon
    Commented Apr 3, 2023 at 18:10

1 Answer 1

4
$\begingroup$
countries = StringTrim[StringReplace[
    Select[StringSplit[StringReplace[
       Import[
        "https://www.worldstandards.eu/cars/list-of-left-driving-countries/", 
        "HTML"], "\r" -> "\n"], "\n"], StringEndsQ[#1, "drives on the left"] & ], 
    {" drives on the left" -> "", RegularExpression["\\([^)]*\\)"] -> ""}]]
interpreter = Interpreter["Country"]
lefties = Sort[Union[Select[interpreter /@ countries,  !FailureQ[#1] & ]]]
all = interpreter /@ CountryData[]
righties = Select[all,  !MemberQ[lefties, #1] & ]
GeoGraphics[{EdgeForm[None], FaceForm[Red], (Polygon[#1, "Polygon"] & ) /@ 
    righties, Entity["AdministrativeDivision", {"Alaska", "UnitedStates"}][
    "Polygon"], FaceForm[Blue], (Polygon[#1, "FullCoordinates"] & ) /@ lefties}, 
  GeoBackground -> "CountryBorders", ImageSize -> Large]

Mathematica graphics

The reason for the special treatment of United States of America Alaska state is because it is missing from the map of the USA in the country data.

$\endgroup$
1
  • $\begingroup$ The line of code "righties = Select[all, !MemberQ[lefties, #1] & ]" can be replaced by the line "righties = Complement[all, lefties]". $\endgroup$
    – anon
    Commented Apr 6, 2023 at 14:07

Your Answer

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

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