We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi All, I have managed to get a sketch working but hitting some stumbling blocks. I display data for a single year (military personal) but I have several years worth of data I would also like to see by clicking a mouse/keyboard button to scroll through the different years and see all the different years of personal changes.
Also I can't figure out how to stop selecting all the circles when point mouse to one circle. Would also like to know how to have it display information (number of soldiers) when I move the cursor over the circle.
NB you may need to download and import the tools mentioned below to get it working:
import org.gicentre.utils.colour.*;
import org.gicentre.geomap.*;
PImage mapImage; // Background map image.
Table locationTable; // Table storing country locations.
Table dataTable; // Table storing Rmy size.
float dataMin = MAX_FLOAT; // Used to store min and max data values.
float dataMax = MIN_FLOAT;
ColourTable cTable; // Will store a Brewer colour table.
GeoMap geoMap;
// Start the sketch and load the data (image and two tables).
void setup()
{
size(800, 400);
stroke(180);
geoMap = new GeoMap(this);
geoMap.readFile("world");
textAlign(LEFT, BOTTOM);
textSize(18);
// Load the background map.
// mapImage = loadImage("countryOutlines.png");
// Load data from tables
locationTable = loadTable("countryLocations.tsv", "header,tsv");
dataTable = loadTable("indicator_army_total.csv", "header,csv");
// Find the minimum and maximum values
for (int row=0; row<dataTable.getRowCount (); row++)
{
dataMin = min(dataMin, dataTable.getInt(row, "2008"));
dataMax = max(dataMax, dataTable.getInt(row, "2008"));
}
}
// Plots the data over the background map.
void draw()
{
background(202, 226, 245); // Ocean colour
stroke(0, 40); // Boundary colour
fill(206, 173, 146); // Land colour
geoMap.draw(); // Draw the entire map.
// Set the appearance of the data circles.
fill(200, 0, 0, 80);
strokeWeight(0.2);
int id = geoMap.getID(mouseX, mouseY);
if (id != -1)
{
fill(180, 120, 120);
geoMap.draw(id);
String name = geoMap.getAttributes().getString(id, 3);
fill(0);
text(name, mouseX+5, mouseY-5);
}
// Draw the background image taking up the full width and height of sketch.
// image(mapImage, 0, 0, width, height);
// Go through each row in table drawing each data item as a circle.
for (int row=0; row<dataTable.getRowCount (); row++)
{
String countryName = dataTable.getString(row, "CountryName");
float data2008 = dataTable.getInt(row, "2008");
float circleSize = map(data2008, dataMin, dataMax, 0, 100);
// Find the row in the location table that matches the country in the data table.
TableRow countryRow = locationTable.findRow(countryName, "CountryName");
// It is possible that we cannot find countryName (from the dataTable) in the
// location table, so only attempt to plot the circle if country is found in both.
if (countryRow != null)
{
// Extract the latitude and longitude from the row we have found.
float latitude = countryRow.getFloat("latitude");
float longitude = countryRow.getFloat("longitude");
// Scale the latitude and longitude to fit in the sketch.
float x = map(longitude, -180, 180, 0, width);
float y = map(latitude, -90, 90, height, 0);
ellipse(x, y, circleSize, circleSize);
}
}
}
Answers
we can't run it because we don't have countryLocations and the army csv file
1.
in line 74 you read a row. Here you want to have a var yearString that holds "2008" . Then on keyPressed() you change it.
2.
you draw the ellipses - when we have a mousePressed and dist() to that ellipse from mouseX, mouseY when dist< radius or so, its near
maybe post the first 5 lines of the files as plain text, so we can help you
this is a simple sketch (not by me) showing a mouse over text
Looks like an edit of something of mine. :)
;-)
For for the delayed replied and thanks for the comments here is the list past of the country locations and army in tsv
CountryName,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010 Afghanistan,47000,,,,55000,58000,45000,45000,45000,45000,383000,429000,429000,400000,400000,400000,,120000,130000,27000,27000,51000,51000,53000,, Albania,40400,,,,,,,65000,65000,65000,86500,67500,67500,67500,67500,67500,40500,27000,22000,21500,22500,11500,14500,14500,, Algeria,170000,,,,126000,126000,126000,126000,126000,126000,162900,164900,270200,268200,303200,305200,305200,317900,308700,318000,319000,334000,334000,334000,, Angola,49500,,,,107000,115000,150000,128000,128000,120000,122000,106400,125500,129000,127500,117500,145500,110000,130000,118000,118000,110000,117000,117000,,
CountryName CountryCode latitude longitude
Afghanistan AF 33.93911 67.709953 Albania AL 41.153332 20.168331 Algeria DZ 28.033886 1.659626 American Samoa AS -14.270972 -170.132217 Andorra AD 42.546245 1.601554 Angola AO -11.202692 17.873887 Anguilla AI 18.220554 -63.068615 Antarctica AQ -75.250973 -0.071389 Antigua and Barbuda AG 17.060816 -61.796428 Argentina AR -38.416097 -63.616672 Armenia AM 40.069099 45.038189 Aruba AW 12.52111 -69.968338 Australia AU -25.274398 133.775136 Austria AT 47.516231 14.550072 Azerbaijan AZ 40.143105 47.576927 Bahamas BS 25.03428 -77.39628 Bahrain BH 25.930414 50.637772 Bangladesh BD 23.684994 90.356331 Barbados BB 13.193887 -59.543198 Belarus BY 53.709807 27.953389 Belgium BE 50.503887 4.469936 Belize BZ 17.189877 -88.49765 Benin BJ 9.30769 2.315834 Bermuda BM 32.321384 -64.75737 Bhutan BT 27.514162 90.433601 Bolivia BO -16.290154 -63.588653 Bosnia and Herzegovina BA 43.915886 17.679076 Botswana BW -22.328474 24.684866 Bouvet Island BV -54.423199 3.413194 Brazil BR -14.235004 -51.92528 British Indian Ocean Territory IO -6.343194 71.876519 Brunei BN 4.535277 114.727669 Bulgaria BG 42.733883 25.48583 Burkina Faso BF 12.238333 -1.561593 Burundi BI -3.373056 29.918886 Cambodia KH 12.565679 104.990963 Cameroon CM 7.369722 12.354722 Canada CA 56.130366 -106.346771 Cape Verde CV 16.002082 -24.013197 Cayman Islands KY 19.513469 -80.566956 Central African Rep. CF 6.611111 20.939444 Chad TD 15.454166 18.732207 Chile CL -35.675147 -71.542969 China CN 35.86166 104.195397 Christmas Island CX -10.447525 105.690449 Cocos (Keeling) Islands CC -12.14 96.88 Colombia CO 4.570868 -74.297333 Comoros KM -11.875001 43.872219 "Congo, Rep." CG -0.228021 15.827659 "Congo, Dem. Rep." CD -0.228021 15.827659 Cook Islands CK -21.236736 -159.777671 Costa Rica CR 9.748917 -83.753428 Cote D'Ivoire CI 7.539989 -5.54708 Croatia HR 45.1 15.2 Cuba CU 21.521757 -77.781167 Cyprus CY 35.126413 33.429859 Czech Rep. CZ 49.817492 15.472962 Denmark DK 56.26392 9.501785 Djibouti DJ 11.825138 42.590275 Dominica DM 15.414999 -61.370976 Dominican Rep. DO 18.735693 -70.162651 Ecuador EC -1.831239 -78.183406 Egypt EG 26.820553 30.802498 El Salvador SV 13.794185 -88.89653 Equatorial Guinea GQ 1.650801 10.267895 Eritrea ER 15.179384 39.782334 Estonia EE 58.595272 25.013607 Ethiopia ET 9.145 40.489673 Falkland Islands (Malvinas) FK -51.796253 -59.523613 Faroe Islands FO 61.892635 -6.911806 Fiji FJ -16.578193 179.414413 Finland FI 61.92411 25.748151 France FR 46.227638 2.213749 French Guiana GF 3.933889 -53.125782 French Polynesia PF -17.679742 -149.406843 French Southern Territories TF -43 67 Gabon GA -0.803689 11.609444 Gambia GM 13.443182 -15.310139 Georgia GE 32.157435 -82.907123 Germany DE 51.165691 10.451526 Ghana GH 7.946527 -1.023194 Gibraltar GI 36.137741 -5.345374 Greece GR 39.074208 21.824312 Greenland GL 71.706936 -42.604303 Grenada GD 12.262776 -61.604171 Guadeloupe GP 16.995971 -62.067641 Guam GU 13.444304 144.793731 Guatemala GT 15.783471 -90.230759 Guernsey GG 49.465691 -2.585278 Guinea GN 9.945587 -9.696645 Guinea-Bissau GW 11.803749 -15.180413 Guyana GY 4.860416 -58.93018 Haiti HT 18.971187 -72.285215 Heard Island and McDonald Islands HM -53.08181 73.504158 Holy See (Vatican City State) VA 41.911 12.452 Honduras HN 15.199999 -86.241905 "Hong Kong, China" HK 22.396428 114.109497 Hungary HU 47.162494 19.503304 Iceland IS 64.963051 -19.020835 India IN 20.593684 78.96288 Indonesia ID -0.789275 113.921327 Iran IR 32.427908 53.688046 Iraq IQ 33.223191 43.679291 Ireland IE 53.41291 -8.24389 Isle of Man IM 54.236107 -4.548056 Israel IL 31.046051 34.851612 Italy IT 41.87194 12.56738 Jamaica JM 18.109581 -77.297508 Japan JP 36.204824 138.252924 Jersey JE 49.214439 -2.13125 Jordan JO 30.585164 36.238414 Kazakhstan KZ 48.019573 66.923684 Kenya KE -0.023559 37.906193 Kiribati KI -3.370417 -168.734039 "Korea, Dem. Rep." KP 35.907757 127.766922 "Korea, Rep." KR 35.907757 127.766922 Kuwait KW 29.31166 47.481766 Kyrgyzstan KG 41.20438 74.766098 Laos LA 19.85627 102.495496 Latvia LV 56.879635 24.603189 Lebanon LB 33.854721 35.862285 Lesotho LS -29.609988 28.233608 Liberia LR 6.428055 -9.429499 Libya LY 25 17 Liechtenstein LI 47.166 9.555373 Lithuania LT 55.169438 23.881275 Luxembourg LU 49.815273 6.129583 "Macao, China" MO 22.198745 113.543873 "Macedonia, FYR" MK 41.608635 21.745275 Madagascar MG -18.766947 46.869107 Malawi MW -13.254308 34.301525 Malaysia MY 4.210484 101.975766 Maldives MV 3.202778 73.22068 Mali ML 17.570692 -3.996166 Malta MT 35.937496 14.375416 Marshall Islands MH 7.131474 171.184478 Martinique MQ 14.641528 -61.024174 Mauritania MR 21.00789 -10.940835 Mauritius MU -20.348404 57.552152 Mayotte YT -12.8275 45.166244 Mexico MX 23.634501 -102.552784 "Micronesia, Fed. Sts." FM 7.425554 150.550812 Moldova MD 47.411631 28.369885 Monaco MC 43.750298 7.412841 Mongolia MN 46.862496 103.846656 Montenegro ME 42.708678 19.37439 Montserrat MS 16.742498 -62.187366 Morocco MA 31.791702 -7.09262 Mozambique MZ -18.665695 35.529562 Myanmar MM 21.913965 95.956223 Namibia NA -22.95764 18.49041 Nauru NR -0.522778 166.931503 Nepal NP 28.394857 84.124008 Netherlands NL 52.132633 5.291266 Netherlands Antilles AN 12.226079 -69.060087 New Caledonia NC -20.904305 165.618042 New Zealand NZ -40.900557 174.885971 Nicaragua NI 12.865416 -85.207229 Niger NE 17.607789 8.081666 Nigeria NG 9.081999 8.675277 Niue NU -19.054445 -169.867233 Norfolk Island NF -29.040835 167.954712 Northern Mariana Islands MP 17.33083 145.38469 Norway NO 60.472024 8.468946 Oman OM 21.512583 55.923255 Pakistan PK 30.375321 69.345116 Palau PW 7.51498 134.58252 "Palestinian Territory, Occupied" PS 42.094445 17.266614 Panama PA 8.537981 -80.782127 Papua New Guinea PG -6.314993 143.95555 Paraguay PY -23.442503 -58.443832 Peru PE -9.189967 -75.015152 Philippines PH 12.879721 121.774017 Pitcairn PN -24.703615 -127.439308 Poland PL 51.919438 19.145136 Portugal PT 39.399872 -8.224454 Puerto Rico PR 18.220833 -66.590149 Qatar QA 25.354826 51.183884 Reunion RE -21.115141 55.536384 Romania RO 45.943161 24.96676 Russia RU 61.52401 105.318756 Rwanda RW -1.940278 29.873888 Saint BarthŽlemy BL 17.9 -62.833 "Saint Helena, Ascension and Tristan da Cunha" SH -24.143474 -10.030696 Saint Kitts and Nevis KN 17.357822 -62.782998 Saint Lucia LC 13.909444 -60.978893 Saint Martin (French part) MF 43.589046 5.885031 Saint Pierre and Miquelon PM 46.941936 -56.27111 Saint Vincent and the Grenadines VC 12.984305 -61.287228 Samoa WS -13.759029 -172.104629 San Marino SM 43.94236 12.457777 Sao Tome and Principe ST 0.18636 6.613081 Saudi Arabia SA 23.885942 45.079162 Senegal SN 14.497401 -14.452362 Serbia RS 44.016521 21.005859 Serbia and Montenegro RS 44.016521 21.005859 Seychelles SC -4.679574 55.491977 Sierra Leone SL 8.460555 -11.779889 Singapore SG 1.352083 103.819836 Slovak republic SK 48.669026 19.699024 Slovenia SI 46.151241 14.995463 Solomon Islands SB -9.64571 160.156194 Somalia SO 5.152149 46.199616 South Africa ZA -30.559482 22.937506 South Georgia and the South Sandwich Islands GS -54.429579 -36.587909 Spain ES 40.463667 -3.74922 Sri Lanka LK 7.873054 80.771797 Sudan SD 12.862807 30.217636 Suriname SR 3.919305 -56.027783 Svalbard and Jan Mayen SJ 77.553604 23.670272 Swaziland SZ -26.522503 31.465866 Sweden SE 60.128161 18.643501 Switzerland CH 46.818188 8.227512 Syria SY 34.802075 38.996815 "Taiwan, Province of China" TW 23.69781 120.960515 Tajikistan TJ 38.861034 71.276093 Tanzania TZ -6.369028 34.888822 Thailand TH 15.870032 100.992541 Timor-Leste TL -8.874217 125.727539 Togo TG 8.619543 0.824782 Tokelau TK -8.967363 -171.855881 Tonga TO -21.178986 -175.198242 Trinidad and Tobago TT 10.691803 -61.222503 Tunisia TN 33.886917 9.537499 Turkey TR 38.963745 35.243322 Turkmenistan TM 38.969719 59.556278 Turks and Caicos Islands TC 21.694025 -71.797928 Tuvalu TV -7.109535 177.64933 Uganda UG 1.373333 32.290275 Ukraine UA 48.379433 31.16558 United Arab Emirates AE 23.424076 53.847818 United Kingdom GB 52.378051 -1.435973 United States US 37.09024 -95.712891 United States Minor Outlying Islands UM 24.747346 -167.594906 Uruguay UY -32.522779 -55.765835 Uzbekistan UZ 41.377491 64.585262 Vanuatu VU -15.376706 166.959158 Venezuela VE 6.42375 -66.58973 Vietnam
did you try my points 1+2 ?
thanks
Hi Chrisir, I had a look at point 1 but didn't get too far. To be honest I'm not an experting in processing. On line 74 you recommended using var yearString. How would I go about this. I'm guessing I would need to declare something before the void setup()
Sorry for the beginner type questions.
yes
String yearString = "2008";
I'll look into it
thanks I did that step I'm getting an error "cannot convert from int to string" Also in your second suggestion still researching this. Many thanks for your help.
ok some remarks. I think the map delivers country names. Line 59.
When we look up those country names, they have to match.
Otherwise it doesnt't work. E.g. map delivers Yemen, in the data file it's yemen rep. - no match. So you need to correct the data file. Also Greenland and Antarctica don't have a match (not in the data file?).
Those are witten in the direct window below the Code.
Also: I didn't find your Congo (Kinshasa) I didn't find your S. Sudan I didn't find your Congo (Brazzaville(?))
Kosovo, Slovakia, Macedonia......
Ivory Coast
W. Sahara
Bosnia and Herz
2009 and 2010 don't have data so we can end at 2008 if you like (function manageYear())
that's how I would do it.
you can use mouseWheel and +/- to change the year.
Mouse: Country and circle get highlighted, Name of Country and number of Soldiers are shown.
mouse click does nothing
maybe mention mouseWheel in the HUD where the year and +/- is displayed
you need to do some house cleaning in the code I guess
I am not sure about findMinMax and dataMin/dataMax - shouldn't they be the same for all years?
Good luck!
Chrisir ;-)
Awesome thanks very much
no problem...
;-)