I'm using a script that converts a CSV file into GeoJSON in order to display it on a map. You can see it for yourself here. The CSV has about four thousand rows. It's quite slow. I'm wondering what is slowing it down and how I can speed it up.
function latLonColumnsToNumbers(data, latName, lonName) {
return data.map(function(item) {
if (item.hasOwnProperty(latName)) {
item[latName] = parseFloat(item[latName]);
if (isNaN(item[latName])) { //check if row has blank lat/long, and if so, flag it
var latFlag = 1;
} else {
latFlag = 0;
}
}
if (item.hasOwnProperty(lonName)) {
item[lonName] = parseFloat(item[lonName]);
if (isNaN(item[lonName])) {
var lonFlag = 1;
} else {
lonFlag = 0;
}
}
if (latFlag == 1 || lonFlag == 1) { //if row has no lat/long, then assign it to the approximate center of the map
item[latName] = 42.2;
item[lonName] = ~83.6;
return item;
}
else {
return item;
}
});
I know that a faster way to do this would be to turn the CSV into a sql database and call it with PHP but that involves using a lot of server-side stuff like NodeJS, Ajax, etc that I am not (yet) familiar with. So I would like to keep using the CSV for now until I learn how to do that.