I am trying to create a Cholorpleth map using Processing and geoJSON. I am having difficulty cycling through my HashMap
to check the property that will dictate the intensity of the polygons color.
Currently this is my code:
void draw() {
map.draw();
for (int i = 0; i < countyMarkers.size(); i++) {
Marker county = countyMarkers.get(i);
String pop = countyData.get("pop").toString();
println(i + "pop: " + pop);
}
What I would like to do is loop through my HashMap
countyData
and get the population of each entry. Use an if statement to compare it to a value and then assign it the color based on the statement that is true.
My HashMap can be seen here:
{name=Carlow, pop=54,612}
{name=Cavan, pop=73,183}
{name=Clare, pop=117,196}
{name=Cork, pop=519,032}
{name=Donegal, pop=161,137}
{name=Dublin, pop=1,273,069}
{name=Galway, pop=250,541}
{name=Kerry, pop=145,502}
{name=Kildare, pop=210,312}
{name=Kilkenny, pop=95,419}
{name=Laois, pop=80,559}
{name=Letrim, pop=31,796}
{name=Limerick, pop=191,809}
{name=Longford, pop=39,000}
{name=Louth, pop=122,897}
{name=Mayo, pop=130,638}
{name=Meath, pop=184,135}
{name=Monaghan, pop=60,483}
{name=Offaly, pop=76,687}
{name=Roscommon, pop=64,065}
{name=Sligo, pop=65,393}
{name=Tipperary, pop=158,754}
{name=Waterford, pop=113,795}
{name=Westmeath, pop=86,164}
{name=Wexford, pop=145,320}
{name=Wicklow, pop=136,640}
I am relatively new to working with this type of data so I am at a loss as to where I am going wrong. I think my logic is correct I am just not sure how to implement it. I'd appreciate any help on the issue.
Currently this line -> println(i + "pop: " + pop);
Outputs the last entry of the hashmap over and over.
This is the output I am getting
0pop: 136,640
1pop: 136,640
2pop: 136,640
3pop: 136,640
4pop: 136,640
5pop: 136,640
6pop: 136,640
7pop: 136,640
8pop: 136,640
9pop: 136,640
10pop: 136,640
11pop: 136,640
12pop: 136,640
13pop: 136,640
14pop: 136,640
15pop: 136,640
16pop: 136,640
17pop: 136,640
18pop: 136,640
19pop: 136,640
20pop: 136,640
21pop: 136,640
22pop: 136,640
23pop: 136,640
24pop: 136,640
25pop: 136,640
I populate my HashMap
using this method.
void getCountyDetails(List<Marker>m) {
countyData = new HashMap();
for (Marker county: countyMarkers) {
countyData.putAll(county.getProperties());
println(countyData);
}
}
Modified code here
Set<String> keySet = countyData.keySet();
for(String pop : keySet){
String value = countyData.get(pop).toString();
println("population:" + value);
}
Now It is outputting:
population:Wicklow
population:136,640
population:Wicklow
population:136,640
population:Wicklow
population:136,640
population:Wicklow
population:136,640
population:Wicklow
population:136,640
population:Wicklow
population:136,640
population:Wicklow
population:136,640
population:Wicklow
population:136,640
population:Wicklow
population:136,640
It still does not seem to be iterating through each entry in the HashMap
New way Of populating HashMap
void getCountyDetails(List<Marker>m) {
countyData = new HashMap();
int i = 0;
for (Marker county: countyMarkers) {
countyData.put(i,county.getProperties());
i++;
}
}