# which-polygon

> Index for matching points against a set of GeoJSON polygons

Latest version **2.2.1** (published 2023-02-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install which-polygon
pnpm add which-polygon
yarn add which-polygon
bun add which-polygon
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.2.1 |
| Published | 2023-02-16 |
| First published | 2015-11-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | separate (@types/which-polygon) |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 52.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 134 |
| Author | Vladimir Agafonkin |
| Maintainers | mbx-npm-ci-production, mbx-npm-ci-staging, mbx-npm-advanced-actions-production, mbx-npm-advanced-actions-staging, mbx-npm-09-production, mbx-npm-08-production, mbx-npm-07-production, mbx-npm-06-production, mbx-npm-05-production, mbx-npm-04-production, mbx-npm-03-production, mbx-npm-02-production, mbx-npm-01-production, mbx-npm-02-staging, mapbox-npm-01, mapbox-npm-02, mapbox-npm-07, mapbox-npm-03, mapbox-npm-04, mapbox-npm-09, mapbox-npm-05, mapbox-npm-06, mapbox-npm-08, mapbox-npm-advanced-actions, mapbox-npm-ci, mapbox-npm, mapbox-admin, mapbox-machine-user |
| Keywords | index, polygon, geojson, query |

## Links

- npm: https://www.npmjs.com/package/which-polygon
- Repository: https://github.com/mapbox/which-polygon
- Homepage: https://github.com/mapbox/which-polygon#readme
- Issues: https://github.com/mapbox/which-polygon/issues
- npm.io page: https://npm.io/package/which-polygon

## Dependencies (2)

- [rbush](https://npm.io/package/rbush.md) ^2.0.1
- [lineclip](https://npm.io/package/lineclip.md) ^1.1.5

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 2.2.1 (latest) — 2023-02-16
- 2.2.0 — 2017-10-16
- 2.1.0 — 2016-10-13
- 2.0.1 — 2016-09-26
- 2.0.0 — 2015-11-04
- 1.0.0 — 2015-11-03

## README

A simple index for matching points and bboxes against a set of GeoJSON polygons to find what polygon it belongs to.
For example, determining the country of a location given a countries GeoJSON.

[![Build Status](https://travis-ci.org/mapbox/which-polygon.svg?branch=master)](https://travis-ci.org/mapbox/which-polygon)
[![Coverage Status](https://coveralls.io/repos/mapbox/which-polygon/badge.svg?branch=master&service=github)](https://coveralls.io/github/mapbox/which-polygon?branch=master)
[![](https://img.shields.io/badge/simply-awesome-brightgreen.svg)](https://github.com/mourner/projects)

### Example usage


```js
var geojson = require('./countries.json');
var query = whichPolygon(geojson);

query([30.5, 50.5]).admin; // 'Ukraine'
```

The input GeoJSON must be a feature collection of polygons or multipolygons.
The query returns the properties of the matched polygon feature.

By default, the query returns properties of the first polygon that has been found (object or null).
To return an array of all found polygon properties, use option `multi` as the second argument:

```js
query([14.3, 51.2], true); // [{props1}, {props2}, {props3}, ...] || null
```

Once the index is built, queries are pretty fast —
17 seconds to query 1 million random locations on a Macbook Pro in this particular case.

You can also query all polygons that intersect a given bbox:

```js
var query = whichPolygon(geojson);
var results = query.bbox([30.5, 50.5, 30.51, 50.51]);
results[0].admin; // 'Ukraine'
```

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