-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
99 lines (98 loc) · 2.52 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var featureCollection = require('turf-featurecollection');
/**
* Takes a {@link FeatureCollection} of any type, a property, and a value and
* returns a FeatureCollection with features matching that
* property-value pair removed.
*
* @module turf/remove
* @category data
* @param {FeatureCollection} features set of input features
* @param {String} property the property to filter
* @param {String} value the value to filter
* @return {FeatureCollection} the resulting FeatureCollection without features that match the property-value pair
* @example
* var points = {
* "type": "FeatureCollection",
* "features": [
* {
* "type": "Feature",
* "properties": {
* 'marker-color': '#00f'
* },
* "geometry": {
* "type": "Point",
* "coordinates": [-0.235004, 5.551918]
* }
* }, {
* "type": "Feature",
* "properties": {
* 'marker-color': '#f00'
* },
* "geometry": {
* "type": "Point",
* "coordinates": [-0.209598, 5.56439]
* }
* }, {
* "type": "Feature",
* "properties": {
* 'marker-color': '#00f'
* },
* "geometry": {
* "type": "Point",
* "coordinates": [-0.197753, 5.556018]
* }
* }, {
* "type": "Feature",
* "properties": {
* 'marker-color': '#000'
* },
* "geometry": {
* "type": "Point",
* "coordinates": [-0.217323, 5.549526]
* }
* }, {
* "type": "Feature",
* "properties": {
* 'marker-color': '#0f0'
* },
* "geometry": {
* "type": "Point",
* "coordinates": [-0.211315, 5.543887]
* }
* }, {
* "type": "Feature",
* "properties": {
* 'marker-color': '#00f'
* },
* "geometry": {
* "type": "Point",
* "coordinates": [-0.202217, 5.547134]
* }
* }, {
* "type": "Feature",
* "properties": {
* 'marker-color': '#0f0'
* },
* "geometry": {
* "type": "Point",
* "coordinates": [-0.231227, 5.56644]
* }
* }
* ]
* };
*
* //=points
*
* var filtered = turf.remove(points, 'marker-color', '#00f');
*
* //=filtered
*/
module.exports = function(collection, key, val) {
var newFC = featureCollection([]);
for(var i = 0; i < collection.features.length; i++) {
if(collection.features[i].properties[key] !== val) {
newFC.features.push(collection.features[i]);
}
}
return newFC;
};