# How can access to curated data needed by GeoRegionValuePlot be speeded up?

Seems that GeoRegionValuePlot requests data from the internet multiple times to process its plot.

As an example, let's graph smoking per capita worldwide.

smokers =
Import["http://en.wikipedia.org/wiki/List_of_countries_by_cigarette_\
consumption_per_capita", "Data"];
table = Rest@smokers[[1, 1, 2]][[All, 2 ;;]];
rule = "Republic of Macedonia" -> "Macedonia";
GeoRegionValuePlot[
{CountryData[StringTrim@#[[1]] /. rule], Interpreter["Number"][#[[2]]]} & /@ table,
ImageSize -> Large,
PlotLabel -> "Cigarrete Consumption Per Capita"]


While waiting for the plot to be graphed, you can see that mathematica accesses servers for information at least twice (Message below shows up twice, then takes additional time to process).

How can the GeoRegionValuePlot performance be improved? Is there a way to cache the information retrieved by the function (maps, polygons, etc) in the local drive so subsequent calls to the GeoRegionValuePlot will perform better?

• – Alexey Popkov Aug 9 '14 at 6:24
• @AlexeyPopkov thanks for the note, but didn't work – Zviovich Aug 10 '14 at 13:18

The Wolfram '.wdx' format was made for this. It maintains wolfram code in a file, but only code, unlike a notebook. Read up here for more info.

The first two lines stay the same, then you would export the data as so:

Export["smokers.wdx", table];


This creates a file in MyDocuments (if in windows, otherwise the folder above where your notebooks are normally stored. To open it if you can't find it/lazy, use:)

SystemOpen[DirectoryName[AbsoluteFileName["smokers.wdx"]]]


Then to open this file, use below:

importedtable = Import["smokers.wdx"];


Then plot it with the below (its identical to your's but using the imported data: "importedtable"):

rule = "Republic of Macedonia" -> "Macedonia";
GeoRegionValuePlot[{CountryData[StringTrim@#[[1]] /. rule], Interpreter["Number"[#[[2]]]} & /@ importedsmokers,
ImageSize -> Large, PlotLabel -> "Cigarrete Consumption Per Capita"]


To use it again and again, just import the ".wdx"

• I believe the poster has issues with CountyData[] and Interpreter[] needing to fetch data multiple times. One can preload curated Country data with CountryData[All,"Preload"]. Remove the Interpreter[] function for such a simple data type transform, ToExpression (not my first choice). I would first manipulate the final list outside the GeoRegionValuePlot[] function to desired format {reg -> val} then pass it in. The List that may be saved to wdx format is that {reg-> val}. – Hans Aug 10 '14 at 16:27
• @Hans, thanks for the answer and comment. I may have to rewrite the question.The issue is not pulling the data itself, but processing the GeoRegionValuePlot. Wanted to use the manipulate function to zoom to specific continents or country groups. The function takes a long time to process. I'll update the question. – Zviovich Aug 10 '14 at 16:51
• @Hans,@PatoCriollo, I see what you mean now. Yes, my way doesn't work, and I don't know how you would. I had a similar problem with GeoGraphics (new to 10 also), and I still don't know how to solve it. Seems like this may be a large problem in 10 that needs a clever work around. – ptolemy0 Aug 10 '14 at 17:12

In 10.0.1 at least, the data does get cached (If you run, say, GeoRegionValuePlot[CountryData[] -> "PopulationDensity"]

the second time is much faster with no download icons (although in this case it still takes ~3 sec to paint all the country polygons)

Also notice that the first time, the first download is much faster than the second. it gets "Positions" of each thing first, then gets the "Polygon"s (if necessary).