1.1.1 • Published 13 days ago

fast-point-in-poly-ts v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
13 days ago

fast-point-in-poly-ts

npm version

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

This version is a TypeScript port of the original fast-point-in-poly package.

Usage

import FastPointInPoly from 'fast-point-in-poly-ts';

const features = getUsStates(); // get GeoJSON FeatureCollection of US states
const point = [30.835188139646572, -84.89577461462216]

const index = new FastPointInPoly(states);

const poly = index.find(point); // returns the Feature representing Georgia!

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: class FastPointPoly

constructor(features)

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

find(point)

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

  • point is one of the following:
    • Point
    • Point Feature
    • Array of [number, number] coordinates representing the longitude and latitude of the point