fast-point-in-poly

Quickly find points in large sets of polygons

Usage no npm install needed!

<script type="module">
  import fastPointInPoly from 'https://cdn.skypack.dev/fast-point-in-poly';
</script>

README

fast-point-in-poly

Simple API for doing point and polygon checks on large sets of polygons. Most useful when doing MANY checks.

Usage

const FastPointInPoly = require('fast-point-in-poly');

const polygons = [...] // List of GeoJSON Polygon Features
const point { ... } // GeoJSON Point Feature

const index = new FastPointInPoly(polygons);

const poly = index.find(point);

Speed

This libraray's speed comes from converting the input polygons to points and putting those points in a wicked fast KDBush index. This index allows us to use geokdbush to sort the polygons points by their distance from the point passed to find. With this sorted list we then do a basic turf.booleanPointInPolygon check and return the first polygon which passes the check. How this index works may change in the future as we build up perf tests and find more robust ways to perform this check.

API

constructor(features)

Constructs an index of the provided features that can be searched.

find(point)

Returns the first polygon in the index which contains the passed point.