# feature-filter-geojson

> Creates filtering function for GeoJSON features

Latest version **1.0.0** (published 2016-09-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install feature-filter-geojson
pnpm add feature-filter-geojson
yarn add feature-filter-geojson
bun add feature-filter-geojson
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-09-02 |
| First published | 2016-09-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Maintainers | gmaclennan |

## Links

- npm: https://www.npmjs.com/package/feature-filter-geojson
- Repository: https://github.com/digidem/feature-filter-geojson
- Homepage: https://github.com/digidem/feature-filter-geojson#readme
- Issues: https://github.com/digidem/feature-filter-geojson/issues
- npm.io page: https://npm.io/package/feature-filter-geojson

## Recent versions

- 1.0.0 (latest) — 2016-09-02

## README

## feature-filter-geojson

[![Build Status](https://travis-ci.org/digidem/feature-filter-geojson.svg?branch=master)](https://travis-ci.org/digidem/feature-filter-geojson)
[![npm](https://img.shields.io/npm/v/feature-filter-geojson.svg)](https://www.npmjs.com/package/feature-filter-geojson)


This library is forked from [mapbox/feature-filter](https://github.com/mapbox/feature-filter), but adapted to work with GeoJSON features rather than features from a vector tile. This library implements the semantics specified by the [Mapbox GL JS spec](https://www.mapbox.com/mapbox-gl-style-spec/#filter).

### API

`featureFilter(filter)`

Given a filter expressed as nested arrays, return a new function
that evaluates whether a given feature (with a .properties or .tags property)
passes its test.

#### Parameters

| parameter | type  | description      |
| --------- | ----- | ---------------- |
| `filter`  | Array | mapbox gl filter |

**Returns** `Function`, filter-evaluating function

### Usage

``` javascript
var ff = require('feature-filter');

// will match a feature with class of street_limited,
// AND an admin_level less than or equal to 3,
// that's NOT a polygon.
var filter = [
    "all",
    ["==", "class", "street_limited"],
    ["<=", "admin_level", 3],
    ["!=", "$type", "Polygon"]
]

// will match a feature that has a class of
// wetland OR wetland_noveg.
// ["in", "class", "wetland", "wetland_noveg"]

// testFilter will be a function that returns a boolean
var testFilter = ff(filter);

// Layer feature that you're testing. Must have type
// and properties keys.
var feature = {
    type: 'Feature'
    geometry: {
      type: 'Polygon',
      coordinates: [[...]]
    },
    properties: {
       class: "street_limited"
       admin_level: 1
    }
};

// will return a boolean based on whether the feature matched the filter
return testFilter(feature);
```

---
_Source: https://npm.io/package/feature-filter-geojson · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
