-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
80 lines (78 loc) · 1.91 KB
/
index.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
var ss = require('simple-statistics');
/**
* Takes a {@link FeatureCollection}, a property name, and a set of percentiles and returns a quantile array.
* @module turf/quantile
* @category classification
* @param {FeatureCollection} input set of features
* @param {String} field the property in `input` from which to retrieve quantile values
* @param {Array<number>} percentiles an Array of percentiles on which to calculate quantile values
* @return {Array<number>} an array of the break values
* @example
* var points = {
* "type": "FeatureCollection",
* "features": [
* {
* "type": "Feature",
* "properties": {
* "population": 5
* },
* "geometry": {
* "type": "Point",
* "coordinates": [5, 5]
* }
* }, {
* "type": "Feature",
* "properties": {
* "population": 40
* },
* "geometry": {
* "type": "Point",
* "coordinates": [1, 3]
* }
* }, {
* "type": "Feature",
* "properties": {
* "population": 80
* },
* "geometry": {
* "type": "Point",
* "coordinates": [14, 2]
* }
* }, {
* "type": "Feature",
* "properties": {
* "population": 90
* },
* "geometry": {
* "type": "Point",
* "coordinates": [13, 1]
* }
* }, {
* "type": "Feature",
* "properties": {
* "population": 100
* },
* "geometry": {
* "type": "Point",
* "coordinates": [19, 7]
* }
* }
* ]
* };
*
* var breaks = turf.quantile(
* points, 'population', [25, 50, 75, 99]);
*
* //=breaks
*/
module.exports = function(fc, field, percentiles) {
var vals = [];
var quantiles = [];
fc.features.forEach(function(feature) {
vals.push(feature.properties[field]);
});
percentiles.forEach(function(percentile) {
quantiles.push(ss.quantile(vals, percentile * 0.01));
});
return quantiles;
};