Wolfram Language

Live Version Coming Soon Check out other examples

Make a Flag Map

Make a world map where each country is colored with its flag.


code

With[{world = CountryData[]}, GeoGraphics[{ EdgeForm[Black], Append[ Transpose[{ GeoStyling[{"Image", #}] & /@ Through[world["Flag"]], Through[world["Polygon"]] }], { GeoStyling[{"Image", Entity["Country", "UnitedStates"]["Flag"]}], \!\(\* NamespaceBox["LinguisticAssistant", DynamicModuleBox[{WolframAlphaClient`Private`query$$ = "Alaska", WolframAlphaClient`Private`boxes$$ = TemplateBox[{"\"Alaska\"", RowBox[{"Entity", "[", RowBox[{"\"AdministrativeDivision\"", ",", RowBox[{"{", RowBox[{"\"Alaska\"", ",", "\"UnitedStates\""}], "}"}]}], "]"}], "\"Entity[\\\"AdministrativeDivision\\\", \ {\\\"Alaska\\\", \\\"UnitedStates\\\"}]\"", "\"administrative division\""}, "Entity"], WolframAlphaClient`Private`allassumptions$$ = {{ "type" -> "Clash", "word" -> "Alaska", "template" -> "Assuming \"${word}\" is ${desc1}. Use as \ ${desc2} instead", "count" -> "6", "Values" -> {{ "name" -> "USState", "desc" -> "a US state", "input" -> "*C.Alaska-_*USState-"}, { "name" -> "MountainClass", "desc" -> "a class of mountains", "input" -> "*C.Alaska-_*MountainClass-"}, { "name" -> "Movie", "desc" -> "a movie", "input" -> "*C.Alaska-_*Movie-"}, { "name" -> "Book", "desc" -> "a book", "input" -> "*C.Alaska-_*Book-"}, { "name" -> "Word", "desc" -> "a word", "input" -> "*C.Alaska-_*Word-"}, { "name" -> "Person", "desc" -> "a person", "input" -> "*C.Alaska-_*Person-"}}}}, WolframAlphaClient`Private`assumptions$$ = {}, WolframAlphaClient`Private`open$$ = {1, 2}}, DynamicBox[ToBoxes[ AlphaIntegration`LinguisticAssistantBoxes["", 1, Dynamic[WolframAlphaClient`Private`query$$], Dynamic[WolframAlphaClient`Private`boxes$$], Dynamic[WolframAlphaClient`Private`allassumptions$$], Dynamic[WolframAlphaClient`Private`assumptions$$], Dynamic[WolframAlphaClient`Private`open$$]], StandardForm], ImageSizeCache->{92., {7., 15.}}, TrackedSymbols:>{ WolframAlphaClient`Private`query$$, WolframAlphaClient`Private`boxes$$, WolframAlphaClient`Private`allassumptions$$, WolframAlphaClient`Private`assumptions$$, WolframAlphaClient`Private`open$$}], DynamicModuleValues:>{}, UndoTrackedVariables:>{WolframAlphaClient`Private`open$$}], BaseStyle->{"Deploy"}, DeleteWithContents->True, Editable->False, SelectWithContents->True]\)["Polygon"] }] }, GeoBackground -> GeoStyling["ReliefMap"], ImageSize -> 500]]

how it works

This example was live-coded at the Wolfram Research booth at SXSW, March 11, 2014.

This expression makes a map with Australia indicated in black:

With[{country = \!\(\* NamespaceBox["LinguisticAssistant", DynamicModuleBox[{WolframAlphaClient`Private`query$$ = "Austrailia", WolframAlphaClient`Private`boxes$$ = TemplateBox[{"\"Australia\"", RowBox[{"Entity", "[", RowBox[{"\"Country\"", ",", "\"Australia\""}], "]"}], "\"Entity[\\\"Country\\\", \\\"Australia\\\"]\"", "\"country\""}, "Entity"], WolframAlphaClient`Private`allassumptions$$ = {{ "type" -> "Clash", "word" -> "Austrailia", "template" -> "Assuming \"${word}\" is ${desc1}. Use as \ ${desc2} instead", "count" -> "2", "Values" -> {{ "name" -> "Country", "desc" -> "a country", "input" -> "*C.Austrailia-_*Country-"}, { "name" -> "SolarSystemFeature", "desc" -> "a solar system feature", "input" -> "*C.Austrailia-_*SolarSystemFeature-"}}}}, WolframAlphaClient`Private`assumptions$$ = {}, WolframAlphaClient`Private`open$$ = {1, 2}}, DynamicBox[ToBoxes[ AlphaIntegration`LinguisticAssistantBoxes["", 1, Dynamic[WolframAlphaClient`Private`query$$], Dynamic[WolframAlphaClient`Private`boxes$$], Dynamic[WolframAlphaClient`Private`allassumptions$$], Dynamic[WolframAlphaClient`Private`assumptions$$], Dynamic[WolframAlphaClient`Private`open$$]], StandardForm], ImageSizeCache->{166., {7., 15.}}, TrackedSymbols:>{ WolframAlphaClient`Private`query$$, WolframAlphaClient`Private`boxes$$, WolframAlphaClient`Private`allassumptions$$, WolframAlphaClient`Private`assumptions$$, WolframAlphaClient`Private`open$$}], DynamicModuleValues:>{}, UndoTrackedVariables:>{WolframAlphaClient`Private`open$$}], BaseStyle->{"Deploy"}, DeleteWithContents->True, Editable->False, SelectWithContents->True]\)}, GeoGraphics[{ GeoStyling[Black], country["Polygon"] }, GeoBackground -> GeoStyling["ReliefMap"] ] ]

You can fill the country polygon with an arbitrary image, in this case, Australias flag:

With[{country = \!\(\* NamespaceBox["LinguisticAssistant", DynamicModuleBox[{WolframAlphaClient`Private`query$$ = "Austrailia", WolframAlphaClient`Private`boxes$$ = TemplateBox[{"\"Australia\"", RowBox[{"Entity", "[", RowBox[{"\"Country\"", ",", "\"Australia\""}], "]"}], "\"Entity[\\\"Country\\\", \\\"Australia\\\"]\"", "\"country\""}, "Entity"], WolframAlphaClient`Private`allassumptions$$ = {{ "type" -> "Clash", "word" -> "Austrailia", "template" -> "Assuming \"${word}\" is ${desc1}. Use as \ ${desc2} instead", "count" -> "2", "Values" -> {{ "name" -> "Country", "desc" -> "a country", "input" -> "*C.Austrailia-_*Country-"}, { "name" -> "SolarSystemFeature", "desc" -> "a solar system feature", "input" -> "*C.Austrailia-_*SolarSystemFeature-"}}}}, WolframAlphaClient`Private`assumptions$$ = {}, WolframAlphaClient`Private`open$$ = {1, 2}}, DynamicBox[ToBoxes[ AlphaIntegration`LinguisticAssistantBoxes["", 1, Dynamic[WolframAlphaClient`Private`query$$], Dynamic[WolframAlphaClient`Private`boxes$$], Dynamic[WolframAlphaClient`Private`allassumptions$$], Dynamic[WolframAlphaClient`Private`assumptions$$], Dynamic[WolframAlphaClient`Private`open$$]], StandardForm], ImageSizeCache->{166., {7., 15.}}, TrackedSymbols:>{ WolframAlphaClient`Private`query$$, WolframAlphaClient`Private`boxes$$, WolframAlphaClient`Private`allassumptions$$, WolframAlphaClient`Private`assumptions$$, WolframAlphaClient`Private`open$$}], DynamicModuleValues:>{}, UndoTrackedVariables:>{WolframAlphaClient`Private`open$$}], BaseStyle->{"Deploy"}, DeleteWithContents->True, Editable->False, SelectWithContents->True]\)}, GeoGraphics[{ GeoStyling[{"Image", country["Flag"]}], country["Polygon"] }, GeoBackground -> GeoStyling["ReliefMap"] ] ]

Put a crisp, black border around the flag image with EdgeForm:

With[{country = \!\(\* NamespaceBox["LinguisticAssistant", DynamicModuleBox[{WolframAlphaClient`Private`query$$ = "Austrailia", WolframAlphaClient`Private`boxes$$ = TemplateBox[{"\"Australia\"", RowBox[{"Entity", "[", RowBox[{"\"Country\"", ",", "\"Australia\""}], "]"}], "\"Entity[\\\"Country\\\", \\\"Australia\\\"]\"", "\"country\""}, "Entity"], WolframAlphaClient`Private`allassumptions$$ = {{ "type" -> "Clash", "word" -> "Austrailia", "template" -> "Assuming \"${word}\" is ${desc1}. Use as \ ${desc2} instead", "count" -> "2", "Values" -> {{ "name" -> "Country", "desc" -> "a country", "input" -> "*C.Austrailia-_*Country-"}, { "name" -> "SolarSystemFeature", "desc" -> "a solar system feature", "input" -> "*C.Austrailia-_*SolarSystemFeature-"}}}}, WolframAlphaClient`Private`assumptions$$ = {}, WolframAlphaClient`Private`open$$ = {1, 2}}, DynamicBox[ToBoxes[ AlphaIntegration`LinguisticAssistantBoxes["", 1, Dynamic[WolframAlphaClient`Private`query$$], Dynamic[WolframAlphaClient`Private`boxes$$], Dynamic[WolframAlphaClient`Private`allassumptions$$], Dynamic[WolframAlphaClient`Private`assumptions$$], Dynamic[WolframAlphaClient`Private`open$$]], StandardForm], ImageSizeCache->{166., {7., 15.}}, TrackedSymbols:>{ WolframAlphaClient`Private`query$$, WolframAlphaClient`Private`boxes$$, WolframAlphaClient`Private`allassumptions$$, WolframAlphaClient`Private`assumptions$$, WolframAlphaClient`Private`open$$}], DynamicModuleValues:>{}, UndoTrackedVariables:>{WolframAlphaClient`Private`open$$}], BaseStyle->{"Deploy"}, DeleteWithContents->True, Editable->False, SelectWithContents->True]\)}, GeoGraphics[{ EdgeForm[Black], GeoStyling[{"Image", country["Flag"]}], country["Polygon"] }, GeoBackground -> GeoStyling["ReliefMap"] ] ]

Apply that technique to every country in the world. Evaluating CountryData without arguments gives a list of world countries. Heres that list in abbreviated form:

CountryData[] // Short

This expression gives a list of {GeoStyling[...], Polygon[...]} pairs, one for each flag and country polygonjust the format required by GeoGraphics to render countries with their flags:

With[{world = CountryData[]}, Transpose[{ GeoStyling[{"Image", #}] & /@ Through[world["Flag"]], Through[world["Polygon"]] }] ] // Short

Use that expression within GeoGraphics to render all the countries of the world:

With[{world = CountryData[]}, GeoGraphics[{ EdgeForm[Black], Transpose[{ GeoStyling[{"Image", #}] & /@ Through[world["Flag"]], Through[world["Polygon"]] }] }, GeoBackground -> GeoStyling["ReliefMap"], ImageSize -> 500]]

The country polygon for the United States doesnt include the widely separated area of Alaska. You can add Alaska explicitly by appending its polygon, rendered with the US flag:

With[{world = CountryData[]}, GeoGraphics[{ EdgeForm[Black], Append[ Transpose[{ GeoStyling[{"Image", #}] & /@ Through[world["Flag"]], Through[world["Polygon"]] }], { GeoStyling[{"Image", Entity["Country", "UnitedStates"]["Flag"]}], \!\(\* NamespaceBox["LinguisticAssistant", DynamicModuleBox[{WolframAlphaClient`Private`query$$ = "Alaska", WolframAlphaClient`Private`boxes$$ = TemplateBox[{"\"Alaska\"", RowBox[{"Entity", "[", RowBox[{"\"AdministrativeDivision\"", ",", RowBox[{"{", RowBox[{"\"Alaska\"", ",", "\"UnitedStates\""}], "}"}]}], "]"}], "\"Entity[\\\"AdministrativeDivision\\\", \ {\\\"Alaska\\\", \\\"UnitedStates\\\"}]\"", "\"administrative division\""}, "Entity"], WolframAlphaClient`Private`allassumptions$$ = {{ "type" -> "Clash", "word" -> "Alaska", "template" -> "Assuming \"${word}\" is ${desc1}. Use as \ ${desc2} instead", "count" -> "6", "Values" -> {{ "name" -> "USState", "desc" -> "a US state", "input" -> "*C.Alaska-_*USState-"}, { "name" -> "MountainClass", "desc" -> "a class of mountains", "input" -> "*C.Alaska-_*MountainClass-"}, { "name" -> "Movie", "desc" -> "a movie", "input" -> "*C.Alaska-_*Movie-"}, { "name" -> "Book", "desc" -> "a book", "input" -> "*C.Alaska-_*Book-"}, { "name" -> "Word", "desc" -> "a word", "input" -> "*C.Alaska-_*Word-"}, { "name" -> "Person", "desc" -> "a person", "input" -> "*C.Alaska-_*Person-"}}}}, WolframAlphaClient`Private`assumptions$$ = {}, WolframAlphaClient`Private`open$$ = {1, 2}}, DynamicBox[ToBoxes[ AlphaIntegration`LinguisticAssistantBoxes["", 1, Dynamic[WolframAlphaClient`Private`query$$], Dynamic[WolframAlphaClient`Private`boxes$$], Dynamic[WolframAlphaClient`Private`allassumptions$$], Dynamic[WolframAlphaClient`Private`assumptions$$], Dynamic[WolframAlphaClient`Private`open$$]], StandardForm], ImageSizeCache->{236., {7., 15.}}, TrackedSymbols:>{ WolframAlphaClient`Private`query$$, WolframAlphaClient`Private`boxes$$, WolframAlphaClient`Private`allassumptions$$, WolframAlphaClient`Private`assumptions$$, WolframAlphaClient`Private`open$$}], DynamicModuleValues:>{}, UndoTrackedVariables:>{WolframAlphaClient`Private`open$$}], BaseStyle->{"Deploy"}, DeleteWithContents->True, Editable->False, SelectWithContents->True]\)["Polygon"] }] }, GeoBackground -> GeoStyling["ReliefMap"], ImageSize -> 500]]