-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompute-data.js
126 lines (108 loc) · 3.69 KB
/
compute-data.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
'use strict';
const fs = require('fs');
const _ = require('lodash');
function distance(coord1, coord2) {
let dx = coord2[0] - coord1[0];
let dy = coord2[1] - coord1[1];
return Math.sqrt( (dx * dx) + (dy * dy) );
}
var arbres = fs.readFileSync('./arbresremarquablesparis2011.json');
arbres = JSON.parse(arbres);
var arbres_align = fs.readFileSync('./arbresalignementparis2010.json');
arbres_align = JSON.parse(arbres_align);
console.log('arbres_align : ' + arbres_align.length);
var poteaux = fs.readFileSync('./poteaux_divers_sur_voie_publique.json');
poteaux = JSON.parse(poteaux);
var poteauxBois = _.filter(poteaux, function (elem) {
return elem.fields.info == 'PEP';
});
console.log('poteauxBois : ' + poteauxBois.length);
var mobilier = fs.readFileSync('./mobilierenvironnementparis2011.json');
mobilier = JSON.parse(mobilier);
var poubelles = _.filter(mobilier, function (elem) {
return ( ['POU', 'POUP', 'PRE'].indexOf(elem.fields.info) !== -1 );
});
console.log('poubelles : ' + poubelles.length);
var bancs = _.filter(mobilier, function (elem) {
return ( ['BA2', 'BA1', 'BA1S', 'BA1F', 'BA2C'].indexOf(elem.fields.info) !== -1 );
});
console.log('bancs : ' + bancs.length);
var result = [];
console.time("Build Data");
// Add poteaux distances Array
for (var i = 0; i < arbres.length; i++) {
var arbre = arbres[i];
let newArbre = {
id: arbre.fields.objectid,
annee_pla: arbre.fields.annee_pla,
adresse: arbre.fields.adresse,
espece: arbre.fields.espece,
arrondisse: arbre.fields.arrondisse,
hauteur: arbre.fields.hauteur || 10,
geom_x_y: arbre.fields.geom_x_y,
genre: arbre.fields.genre,
nom_commun: arbre.fields.nom_commun,
nom_ev: arbre.fields.nom_ev,
famille: arbre.fields.famille,
poteaux_bois_dist: [],
arbres_align_dist: [],
bancs_dist: []
}
// Poteaux
let poteaux_bois_dist = [];
for (var j = 0; j < poteauxBois.length; j++) {
let poteau = poteauxBois[j];
let dist = distance(poteau.fields.geom_x_y, newArbre.geom_x_y);
poteaux_bois_dist.push(dist);
}
poteaux_bois_dist = _.groupBy(poteaux_bois_dist, function (elem) {
return Math.floor(elem * 1000);
});
poteaux_bois_dist = _.sortBy(poteaux_bois_dist, 'distance');
_.each(poteaux_bois_dist, function(elem, index) {
newArbre.poteaux_bois_dist.push({
distance: parseInt(index) / 1000,
count: elem.length
});
});
// Arbre align
let arbres_align_dist = [];
for (var j = 0; j < arbres_align.length; j++) {
let align = arbres_align[j];
let dist = distance(align.fields.geom_x_y, newArbre.geom_x_y);
arbres_align_dist.push(dist);
}
arbres_align_dist = _.groupBy(arbres_align_dist, function (elem) {
return Math.floor(elem * 1000)
});
arbres_align_dist = _.sortBy(arbres_align_dist, 'distance');
_.each(arbres_align_dist, function(elem, index) {
newArbre.arbres_align_dist.push({
distance: parseInt(index) / 1000,
count: elem.length
});
});
// Bancs
let bancs_dist = [];
for (var j = 0; j < bancs.length; j++) {
let banc = bancs[j];
let dist = distance(banc.fields.geom_x_y, newArbre.geom_x_y);
bancs_dist.push(dist);
}
bancs_dist = _.groupBy(bancs_dist, function (elem) {
return Math.floor(elem * 1000)
});
bancs_dist = _.sortBy(bancs_dist, 'distance');
_.each(bancs_dist, function(elem, index) {
newArbre.bancs_dist.push({
distance: parseInt(index) / 1000,
count: elem.length
});
});
// Add arbre
result.push(newArbre);
}
console.timeEnd("Build Data");
console.time("Write file");
fs.writeFileSync('data.json', JSON.stringify(result));
console.timeEnd("Write file");