2
$\begingroup$

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?

$\endgroup$
5
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Yes... that works as well, and is just a bit cleaner. $\endgroup$ – David G. Stork May 17 '15 at 1:47
4
$\begingroup$

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

$\endgroup$
  • $\begingroup$ David, do you think some note of this should be made here? $\endgroup$ – Mr.Wizard May 20 '15 at 6:41
  • $\begingroup$ @Mr.Wizard Fair point. I posted a teeny comment to that effect. $\endgroup$ – David G. Stork May 20 '15 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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