Skip to content

Keeps any features from a feature collection that match a property value.

License

Notifications You must be signed in to change notification settings

turf-junkyard/turf-filter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

turf-filter

build status

turf filter module

turf.filter(features, key, value)

Takes a FeatureCollection and filters it by a given property and value.

Parameters

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

Example

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

Installation

Requires nodejs.

$ npm install turf-filter

Tests

$ npm test

About

Keeps any features from a feature collection that match a property value.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •