-
Notifications
You must be signed in to change notification settings - Fork 0
/
json-parser.js
68 lines (53 loc) · 1.42 KB
/
json-parser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const utmObj = require('utm-latlng');
const utm = new utmObj('EUREF89'); //Default Ellipsoid is 'WGS 84'
const accidentsJson = require('./myOutputFile.json');
const turf = require('@turf/turf');
const fs = require('fs');
let lightQualityTypes = [];
const geoJson = {
"type": "FeatureCollection",
"features": []
}
let obj = {
'"Dagslys"': [],
'"Mørkt med vegbelysning"': [],
'"Ukjent"': [],
'"Tussmørke, skumring"': [],
'"Mørkt uten vegbelysning"': [],
}
accidentsJson.forEach((a, i) => {
const point = a['GEOMETRI'];
// const speedLimit = a['SPEEDLIMIT'];
const lightQuality = a['LIGHTQUALITY'];
let X = point.split(' ')[1];
let Y = point.split(' ')[2];
if (X) {
X = X.replace('(', '').trim();
}
if (Y) {
Y = Y.replace(')"', '').trim();
}
const coords = utm.convertUtmToLatLng(X, Y, 33, 'V');
const coordsArr = [coords.lng, coords.lat];
if (!lightQualityTypes.includes(lightQuality)) {
lightQualityTypes.push(lightQuality);
}
if (obj[lightQuality]) {
obj[lightQuality].push(coords);
}
console.log(lightQuality);
if (lightQuality === '"Mørkt med vegbelysning"') {
console.log(i);
if (typeof coords === 'object') {
const point = turf.point(coordsArr);
geoJson.features.push(point);
}
}
});
console.log(geoJson);
fs.writeFileSync(
'clusterGeoJson-dark.json',
JSON.stringify(geoJson, null, 2),
(err) => console.log(err)
);
// console.log(obj);