xxxxxxxxxx
59
let table;
//load the CSV before the program runs
function preload() {
table = loadTable('fpNYC.csv', 'csv', 'header');
}
function setup() {
createCanvas(400, 400);
background(255);
//print(table);
//get the amount of rows in the CSV
let numRows = table.getRowCount();
//get the columns of data
let lat = table.getColumn('Latitude');
let lng = table.getColumn("Longitude");
let br = table.getColumn("Borough");
let minLat = min(lat);
let maxLat = max(lat);
print(minLat, maxLat);
let minLng = min(lng);
let maxLng = max(lng);
print(minLng, maxLng);
//iterate over the number of rows
for (let i = 0; i < numRows; i++) {
let newLng = map(lng[i], -74.329001, -73.669821, 0, width);
let newLat = map(lat[i], 40.477399, 40.969485, height, 0);
if (br[i] == "QUEENS") {
fill(255, 0, 0);
} else if (br[i] == "MANHATTAN") {
fill(0, 0, 255);
} else if (br[i] == "STATEN ISLAND") {
fill(100, 255, 255);
} else if (br[i] == "BROOKLYN") {
fill(255, 0, 255);
} else if (br[i] == "BRONX") {
fill(100, 100, 100);
} else {
fill(0);
}
noStroke();
ellipse(newLng, newLat, 2, 2);
}
}