What would a minimal example for a choropleth map in Mathematica look like?
I can read in a ESRI Shapefile using Import
, but do not know how to work with th
Just for reference, here some tips for working with ESRI Shapefiles. CountryData
does not provide county-level data for Germany (the administrative unit is called "Kreis"), which is why I wrote my own KreisData
function. The shape file I used can be downloaded for free, however there are terms of use to consider.
The KreisData
function is then created as follows:
shp = Import["C:/TEMP/map/VG2500/vg2500_krs.shp", "Data"];
polys = "Geometry" /. First[shp];
ags = "RS" /. ("LabeledData" /. First[shp]);
names = "GEN" /. ("LabeledData" /. First[shp]);
area = "SHAPE_AREA" /. ("LabeledData" /. First[shp]);
KreisDataRules =
Dispatch[MapThread[
Rule[#1, #2] &, {ags, Transpose[{polys, area, names}]}]];
KreisData[tag_String, "Polygon"] := First[tag /. KreisDataRules];
KreisData[tag_String, "Area"] := Part[tag /. KreisDataRules, 2];
KreisData[tag_String, "Name"] := Last[tag /. KreisDataRules];
KreisData[] := ags;
With this function, and the example code by Sjoerd C. de Vries, a map of Germany is created thus:
renderMap[scheme_String] :=
Graphics[{ColorData[scheme][
Rescale[KreisData[#, "Area"], {3.63067036816521*10^7,
3.08469540395003*10^9}]] /.
HoldPattern[Blend[___]] -> Yellow, KreisData[#, "Polygon"]} & /@
KreisData[]];
Manipulate[renderMap[s], {s, ColorData["Gradients"]}]