2

There seems to be an incompatibility between the representation in CountryData[] for versions 9.0 and 10.1. The documentation on ref/CountryData gives the following example, which does not work on 10.1:

Graphics[{If[CountryData[#, "AntarcticNations"], Orange, LightBrown], 
    CountryData[#, "SchematicPolygon"]} & /@ CountryData[]]

which does not produce the bi-colored map illustrated on the documentation.

My below code worked fine in v. 9.0, but does not yield a bi-colored map in v. 10.1, suggesting that the representation of CountryData has changed, thereby making the MemberQ coloring selection in myMap inoperable.

myCountries = 
  Sort[{"Australia", "Austria", "Belgium", "BosniaHerzegovena", 
    "Cambodia", "Canada", "China", "Croatia", "CzechRepublic", 
    "Denmark", "Ecuador", "Egypt", "Finland", "France", "Germany", 
    "Greece", "HongKong", "Hungary", "Iceland", "India", "Indonesia", 
    "Ireland", "Israel", "Italy", "Japan", "Mexico", "Montenegro", 
    "Nepal", "Netherlands", "NewZealand", "Norway", "Peru", "Russia", 
    "SaudiArabia", "Singapore", "Slovenia", "Slovakia", "SouthKorea", 
    "Spain", "SriLanka", "Sweden", "Switzerland", "Taiwan", 
    "Thailand", "UnitedArabEmerites", "UnitedKingdom", 
    "UnitedStates", "VaticanCity"}];
myMap = Graphics[{If[
       MemberQ[myCountries, CountryData[#]], Blue, Orange],
      CountryData[#, {"SchematicPolygon", "LambertAzimuthal"}]} & /@ 
    CountryData[ ]];
myCaptionText = 
  Graphics[{Purple, 
    Text[StyleForm[
      StringJoin["The ", ToString[Length[myCountries]], 
       " countries I have visited"], 20]]}, {0, 0}];
myStringSet = Partition[StringJoin[#, ""] & /@ myCountries,
   Round[ Length[myCountries]/8], 
   Round[ Length[myCountries]/8], {1, 1}, " "];
myCountryLabels = Graphics[Text[myStringSet, {0, -1}]];
myCountriesMap = 
 Show[myMap, myCaptionText, myCountryLabels, ImageSize -> {600, 600}]

enter image description here

In v. 9.0 the countries in the list myCountries were rendered in Blue.

How can I restore that functionality?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
David G. Stork
  • 41,180
  • 3
  • 34
  • 96

2 Answers2

5

Change the MemberQ criteria to CountryData[#, "Name"]]

EDIT: Added spaces to some names in myCountries and corrected spellings.

$Version

"10.1.0 for Mac OS X x86 (64-bit) (March 24, 2015)"

myCountries = 
  Sort[{"Australia", "Austria", "Belgium", "Bosnia and Herzegovina", 
    "Cambodia", "Canada", "China", "Croatia", "Czech Republic", "Denmark", 
    "Ecuador", "Egypt", "Finland", "France", "Germany", "Greece", "Hong Kong",
     "Hungary", "Iceland", "India", "Indonesia", "Ireland", "Israel", "Italy",
     "Japan", "Mexico", "Montenegro", "Nepal", "Netherlands", "New Zealand", 
    "Norway", "Peru", "Russia", "Saudi Arabia", "Singapore", "Slovenia", 
    "Slovakia", "South Korea", "Spain", "Sri Lanka", "Sweden", "Switzerland", 
    "Taiwan", "Thailand", "United Arab Emirates", "United Kingdom", 
    "United States", "Vatican City"}];

myMap = Graphics[{
      If[
       MemberQ[myCountries, CountryData[#, "Name"]],
       Lighter[Blue, .4],
       LightOrange],
      CountryData[#,
       {"SchematicPolygon", "LambertAzimuthal"}]} & /@
    CountryData[]];

myCaptionText = Graphics[{
    Purple,
    Text[StyleForm[
      StringJoin["The ", ToString[Length[myCountries]], 
       " countries I have visited"], 20]]},
   {0, 0}];

myStringSet = 
  Partition[StringJoin[#, ""] & /@ myCountries, Round[Length[myCountries]/8],
   Round[Length[myCountries]/8],
   {1, 1}, " "];

myCountryLabels = Graphics[Text[myStringSet, {0, -1}]];

myCountriesMap = 
 Show[myMap, myCaptionText, myCountryLabels, ImageSize -> {600, 600}]

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
4

Found the answer. Countries now use Entity["Country", #] & /@ myCountries, and the conditional statement should compare Entities.

David G. Stork
  • 41,180
  • 3
  • 34
  • 96