npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

geojson-flatbush

v0.3.0

Published

GeoJSON implementation of Flatbush - A really fast static spatial index.

Readme

GeoJSON Flatbush

build coverage npm code Greenkeeper badge

GeoJSON implementation of Flatbush — A really fast static spatial index for 2D points and rectangles in JavaScript.

GETTING STARTED

Install

npm install --save geojson-flatbush

Example

This is a simple example that populates the index with lines and queries the index with a polygon. Note, for this example, Turf must be installed npm install @turf/turf

// Initialize GeojsonFlatbush with features.
const index = new GeojsonFlatbush(2)

// Add feature collection to index.
const collection = turf.featureCollection([
  turf.lineString([[0, 0], [1, 1]]),
  turf.lineString([[0, 1], [1, 2]]),
]);
index.load(collection);

// Perform the indexing.
index.finish();

// Query with polygon.
const polygon = turf.polygon([[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]]);
const found = index.search(polygon, collection);

// Find k-nearest neighbors and return IDs instead features
const ids = index.neighbors(point, 5);

// Do something with found feature.
found.features.forEach((feature) => {
  console.log(feature);
});

// Reconstruct the index from a raw array buffer
const newindex = GeojsonFlatbush.from(index.data);

USAGE

For a full listing of all available API options see the documentation page. The following methods are available:

const index = new GeojsonFlatbush(numItems, [nodeSize], [ArrayType])
  // numItems: Number of items to index
  // nodeSize: Size of the tree node (16 by default)
  // ArrayType: the array type used for coordinates storage (Float64Array by default)

index.add(GeoJSON)                       // Add GeoJSON to index
index.finish()                           // Perform indexing
index.load(FeatureCollection)            // Load feature collection or array
index.neighbors(point, k)                // Find k-nearest neighbors from point
index.search(GeoJSON, FeatureCollection) // Find features within bounding box
GeojsonFlatbush.from(index.data)         // Create new index from raw data

TIPS

  • GeojsonFlatbush is really just a wrapper to Flatbush but just more GeoJSON friendly.

  • GeojsonFlatbush, just like its underlying spatial index, Flatbush, does not store the original data when using add() or load(). It only stores a bounding box and its ID (i.e., the order in which the data was added).

  • The query methods (neighbors, search) will return a FeatureCollection if a source collection is provided, but the order of the features in the source collection must match the order in which the original data was added.

  • It is probably not a good idea to combine using add and load since the order of the data will be needed to map the query output IDs to the original features. It is best to just add all your data to a single FeatureCollection for loading and querying. Unless you want to keep track of the ID order.

BUILD

To build and test the library locally:

npm install
npm test

LICENSE

Copyright (c) 2019 Daniel Pulido mailto:[email protected]

Source code is released under the ISC License.