xxxxxxxxxx
61
// source of the csv file for the location of all mcdonalds in europe
// https://github.com/pierredavidbelanger/ekmeans/blob/master/McDonald's%20Europe.csv
strings = [];
let minLat;
let maxLat;
let minLong;
let maxLong;
function preload() {
strings = loadStrings("mcdeurope.csv");
}
function setup() {
createCanvas(600, 400);
background(220);
if (strings == null) {
print("Failed to load file."); // checking if file loaded
while (true) {}
}
print("Loaded " + strings.length + " lines successfully");
getMinMaxLatLong();
}
function getMinMaxLatLong() {
let singleRow = [];
for (let mcdRowNumber = 0; mcdRowNumber < strings.length; mcdRowNumber++) {
singleRow = split(strings[mcdRowNumber], ",");
let latitude = float(singleRow[0]); // first is latitude
let longitude = float(singleRow[1]); // second is longitude
if (isNaN(longitude) || isNaN(latitude)) {
// make sure they are numbers
print("Conversion to float failed; Skipping row " + mcdRowNumber);
} else {
if (mcdRowNumber == 0) {
// very interesting observation, by changing the initial values of min and max of the lat and long, the entire visualization shifts, why?
minLat = -20;
maxLat = 30;
minLong = 20;
maxLong = 70;
}
minLat = min(minLat, latitude);
maxLat = max(maxLat, latitude);
minLong = min(minLong, longitude);
maxLong = max(maxLong, longitude);
}
let xpos = map(longitude, minLong, maxLong, 0, width);
let ypos = map(latitude, minLat, maxLat, height, 0);
stroke(3);
point(xpos, ypos);
} // end of for loop
//inaccurate with the extreme values
//print("Latitude (min, max) = (" + minLat + "," + maxLat + ") ");
//print("Longitude (min, max) = (" + minLong + "," + maxLong + ")");
print("Finished.");
} // end of findMinMaxLatLong