turf filter module
Takes a FeatureCollection and filters it by a given property and value.
parameter | type | description |
---|---|---|
features |
FeatureCollection | input features |
key |
String | the property on which to filter |
value |
String | the value of that property on which to filter |
var features = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"species": "oak"
},
"geometry": {
"type": "Point",
"coordinates": [-72.581777, 44.260875]
}
}, {
"type": "Feature",
"properties": {
"species": "birch"
},
"geometry": {
"type": "Point",
"coordinates": [-72.570018, 44.260691]
}
}, {
"type": "Feature",
"properties": {
"species": "oak"
},
"geometry": {
"type": "Point",
"coordinates": [-72.576284, 44.257925]
}
}, {
"type": "Feature",
"properties": {
"species": "redwood"
},
"geometry": {
"type": "Point",
"coordinates": [-72.56916, 44.254605]
}
}, {
"type": "Feature",
"properties": {
"species": "maple"
},
"geometry": {
"type": "Point",
"coordinates": [-72.581691, 44.24858]
}
}, {
"type": "Feature",
"properties": {
"species": "oak"
},
"geometry": {
"type": "Point",
"coordinates": [-72.583837, 44.255773]
}
}
]
};
var key = "species";
var value = "oak";
var filtered = turf.filter(features, key, value);
//=features
//=filtered
Returns FeatureCollection
, a filtered collection with only features that match input key
and value
Requires nodejs.
$ npm install turf-filter
$ npm test