Skip the header and bad data
This commit is contained in:
@@ -10,7 +10,6 @@ import WebGLPointsLayerRenderer from '../src/ol/renderer/webgl/PointsLayer';
|
|||||||
import {clamp, lerp} from '../src/ol/math';
|
import {clamp, lerp} from '../src/ol/math';
|
||||||
import Stamen from '../src/ol/source/Stamen';
|
import Stamen from '../src/ol/source/Stamen';
|
||||||
|
|
||||||
const features = [];
|
|
||||||
const vectorSource = new Vector({
|
const vectorSource = new Vector({
|
||||||
features: [],
|
features: [],
|
||||||
attributions: 'NASA'
|
attributions: 'NASA'
|
||||||
@@ -109,26 +108,28 @@ function loadData() {
|
|||||||
client.open('GET', 'data/csv/meteorite_landings.csv');
|
client.open('GET', 'data/csv/meteorite_landings.csv');
|
||||||
client.onload = function() {
|
client.onload = function() {
|
||||||
const csv = client.responseText;
|
const csv = client.responseText;
|
||||||
|
const features = [];
|
||||||
|
|
||||||
|
let prevIndex = csv.indexOf('\n') + 1; // scan past the header line
|
||||||
|
|
||||||
let curIndex;
|
let curIndex;
|
||||||
let prevIndex = 0;
|
while ((curIndex = csv.indexOf('\n', prevIndex)) != -1) {
|
||||||
let line;
|
const line = csv.substr(prevIndex, curIndex - prevIndex).split(',');
|
||||||
while ((curIndex = csv.indexOf('\n', prevIndex)) > 0) {
|
|
||||||
line = csv.substr(prevIndex, curIndex - prevIndex).split(',');
|
|
||||||
prevIndex = curIndex + 1;
|
prevIndex = curIndex + 1;
|
||||||
|
|
||||||
// skip header
|
const coords = fromLonLat([parseFloat(line[4]), parseFloat(line[3])]);
|
||||||
if (prevIndex === 0) {
|
if (isNaN(coords[0]) || isNaN(coords[1])) {
|
||||||
|
// guard against bad data
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const coords = fromLonLat([parseFloat(line[4]), parseFloat(line[3])]);
|
|
||||||
|
|
||||||
features.push(new Feature({
|
features.push(new Feature({
|
||||||
mass: parseFloat(line[1]) || 0,
|
mass: parseFloat(line[1]) || 0,
|
||||||
year: parseInt(line[2]) || 0,
|
year: parseInt(line[2]) || 0,
|
||||||
geometry: new Point(coords)
|
geometry: new Point(coords)
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
vectorSource.addFeatures(features);
|
vectorSource.addFeatures(features);
|
||||||
};
|
};
|
||||||
client.send();
|
client.send();
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import {fromLonLat} from '../src/ol/proj';
|
|||||||
import WebGLPointsLayerRenderer from '../src/ol/renderer/webgl/PointsLayer';
|
import WebGLPointsLayerRenderer from '../src/ol/renderer/webgl/PointsLayer';
|
||||||
import {lerp} from '../src/ol/math';
|
import {lerp} from '../src/ol/math';
|
||||||
|
|
||||||
const features = [];
|
|
||||||
const vectorSource = new Vector({
|
const vectorSource = new Vector({
|
||||||
features: [],
|
features: [],
|
||||||
attributions: 'National UFO Reporting Center'
|
attributions: 'National UFO Reporting Center'
|
||||||
@@ -70,17 +69,14 @@ function loadData() {
|
|||||||
client.open('GET', 'data/csv/ufo_sighting_data.csv');
|
client.open('GET', 'data/csv/ufo_sighting_data.csv');
|
||||||
client.onload = function() {
|
client.onload = function() {
|
||||||
const csv = client.responseText;
|
const csv = client.responseText;
|
||||||
let curIndex;
|
const features = [];
|
||||||
let prevIndex = 0;
|
|
||||||
let line;
|
|
||||||
while ((curIndex = csv.indexOf('\n', prevIndex)) > 0) {
|
|
||||||
line = csv.substr(prevIndex, curIndex - prevIndex).split(',');
|
|
||||||
prevIndex = curIndex + 1;
|
|
||||||
|
|
||||||
// skip header
|
let prevIndex = csv.indexOf('\n') + 1; // scan past the header line
|
||||||
if (prevIndex === 0) {
|
|
||||||
continue;
|
let curIndex;
|
||||||
}
|
while ((curIndex = csv.indexOf('\n', prevIndex)) != -1) {
|
||||||
|
const line = csv.substr(prevIndex, curIndex - prevIndex).split(',');
|
||||||
|
prevIndex = curIndex + 1;
|
||||||
|
|
||||||
const coords = fromLonLat([parseFloat(line[5]), parseFloat(line[4])]);
|
const coords = fromLonLat([parseFloat(line[5]), parseFloat(line[4])]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user