What would be the minimum example for a choropleth map in Mathematica?

What would be the minimum example for a choropleth map in Mathematica?

I can read in the ESRI Shapefile using Import , but I don’t know how to work with the imported result.

+6
wolfram-mathematica geospatial
source share
5 answers
 Graphics[ { ColorData["ThermometerColors"][ Rescale[CountryData[#, "GDPPerCapita"], {100, 50000}] ] /. HoldPattern[Blend[___]] -> Yellow, CountryData[#, "Polygon"] } & /@ CountryData[] ] 

enter image description here

And why a replacement? If there is no data of the required type for a given country, CountryData returns Missing ["NotAvailable"] by calling ColorData , and its base function Blend does not return a specific RGB value. I will replace this invaluable Blend with Yellow.

+7
source share

Just for reference, here are some tips for working with ESRI Shapefiles. CountryData does not provide county level data for Germany (the administrative unit is called "Kreis"), so I wrote my own function KreisData . The form file that I used can be downloaded for free , but there are terms of use for review.

Then the KreisData function is 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; 

Using this function and Sjoerd C. de Vries sample code, a map of Germany is created in this way:

 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"]}] 

Result with "GrayTones" color scheme

+5
source share

Throw the minimum value in the code golf value:

 Graphics@Function[f,{Hue[f[#,"Area"]/10^7],f[#,"Polygon"]} &/@ f[]]@CountryData 

enter image description here

+3
source share

Because I can't resist Code Golf competing with belisarius:

 Graphics[{Hue[i~#~"Area"/10^7],i~#~"Polygon"}~Table~{i,#[]}&@CountryData] 

(for the same result)

+2
source share

@Karsten W .: unfortunately your shp file is no longer available. I tried a similar one (vg250_0101.utm32s.shape.ebenen \ vg250_ebenen \ vg250_krs.shp) from the same source, but I got the error message "Transpose: the first two levels cannot be transposed" from your KreisDataRules function. And since I didn’t quite understand what your code is doing, maybe you can help. I am trying to draw up a thematic map at the Kreis level, where the coloring shows the number of tourists in our city, if necessary also 0. I would really appreciate any help.

0
source share

All Articles