I am trying to visualize data of a dataset on a shapefile in Mathematica, but cannot find an understandable example. Let's assume I have a normal Shapefile with one Field "District No." inside and 5 polygons that are numbered from 1 to 5 in that field.
Now this is an example of my dataset structure:
myDataset =
Dataset[{<|"District No." -> 1,
"Party 1" -> RandomInteger[10000; 100000],
"Party 2" -> RandomInteger[10000; 100000],
"Party 3" -> RandomInteger[10000; 100000],
"Party 4" -> RandomInteger[10000; 100000],
"Party 5" -> RandomInteger[10000; 100000],
"Party 6" -> RandomInteger[10000; 100000],
"Party 7" -> RandomInteger[10000; 100000],
"Invalid" -> RandomInteger[10000; 100000],
"Absent" -> RandomInteger[10000; 100000]|>,
<|"District No." -> 2, "Party 1" -> RandomInteger[10000; 100000],
"Party 2" -> RandomInteger[10000; 100000],
"Party 3" -> RandomInteger[10000; 100000],
"Party 4" -> RandomInteger[10000; 100000],
"Party 5" -> RandomInteger[10000; 100000],
"Party 6" -> RandomInteger[10000; 100000],
"Party 7" -> RandomInteger[10000; 100000],
"Invalid" -> RandomInteger[10000; 100000],
"Absent" -> RandomInteger[10000; 100000]|>,
<|"District No." -> 3, "Party 1" -> RandomInteger[10000; 100000],
"Party 2" -> RandomInteger[10000; 100000],
"Party 3" -> RandomInteger[10000; 100000],
"Party 4" -> RandomInteger[10000; 100000],
"Party 5" -> RandomInteger[10000; 100000],
"Party 6" -> RandomInteger[10000; 100000],
"Party 7" -> RandomInteger[10000; 100000],
"Invalid" -> RandomInteger[10000; 100000],
"Absent" -> RandomInteger[10000; 100000]|>,
<|"District No." -> 4, "Party 1" -> RandomInteger[10000; 100000],
"Party 2" -> RandomInteger[10000; 100000],
"Party 3" -> RandomInteger[10000; 100000],
"Party 4" -> RandomInteger[10000; 100000],
"Party 5" -> RandomInteger[10000; 100000],
"Party 6" -> RandomInteger[10000; 100000],
"Party 7" -> RandomInteger[10000; 100000],
"Invalid" -> RandomInteger[10000; 100000],
"Absent" -> RandomInteger[10000; 100000]|>,
<|"District No." -> 5, "Party 1" -> RandomInteger[10000; 100000],
"Party 2" -> RandomInteger[10000; 100000],
"Party 3" -> RandomInteger[10000; 100000],
"Party 4" -> RandomInteger[10000; 100000],
"Party 5" -> RandomInteger[10000; 100000],
"Party 6" -> RandomInteger[10000; 100000],
"Party 7" -> RandomInteger[10000; 100000],
"Invalid" -> RandomInteger[10000; 100000],
"Absent" -> RandomInteger[10000; 100000]|>
}]
How can I visualize the values either of one of the parties (columns) of the dataset and assign them to each polygon or assign, for example the Max of each party to the respective district and visualize that in a nice TemperatureMap?
I found this code example, but I don't understand it (you need to scroll down there):
Labeled[Row[{Graphics[MapThread[{FaceForm[ColorData["Temperature"][1-#1]],#2}&,{resc,polys}],ImageSize->Large],BarLegend[{ColorData["Temperature"][1-#]&/@Sort[resc][[1;;-1;;5]],{N[dmin,2],N[dmax+.01,2]}},8]}],\[IndentingNewLine]Style["Jones minus Spencer per ballot by Ward",20,FontFamily->"Source Sans Pro"],Top]
I get it that the only really relevant line is this:
Row[{Graphics[MapThread[{FaceForm[ColorData["Temperature"][1-#1]],#2}&,{resc,polys}],ImageSize->Large]
But where is the part where I assign a dataset-column to the district column in the shapefile?
So far, I have imported the shapefile like this:
shp = FileNames["Bezirk*", {NotebookDirectory[] <> "Shp"}];
FileFormat /@ shp
shpfile = SelectFirst[shp, FileFormat[#] === "SHP" &];
shpdata = Import[shpfile, "Data"]; (*Import the Shapefile Data*)
shppolygons = "Geometry" /. shpdata[[1]];
All I need is the most basic and primitive example.
And yes, this question is related with this one