fast-point-in-poly
v1.0.0
Published
Quickly find points in large sets of polygons
Downloads
149
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.
- features is an array of GeoJSON Polygon Features.
find(point)
Returns the first polygon in the index which contains the passed point.
- point is a GeoJSON Point Feature.