# geojson-rbush

> GeoJSON implementation of RBush

Latest version **3.2.0** (published 2021-07-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install geojson-rbush
pnpm add geojson-rbush
yarn add geojson-rbush
bun add geojson-rbush
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.2.0 |
| Published | 2021-07-29 |
| First published | 2017-03-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 14.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Denis Carriere |
| Maintainers | deniscarriere |
| Keywords | geojson, index, tree, spatial, rbush |

## Links

- npm: https://www.npmjs.com/package/geojson-rbush
- npm.io page: https://npm.io/package/geojson-rbush

## Dependencies (5)

- [rbush](https://npm.io/package/rbush.md) ^3.0.1
- [@turf/bbox](https://npm.io/package/@turf/bbox.md) *
- [@turf/meta](https://npm.io/package/@turf/meta.md) 6.x
- [@turf/helpers](https://npm.io/package/@turf/helpers.md) 6.x
- [@types/geojson](https://npm.io/package/@types/geojson.md) 7946.0.8

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 3.2.0 (latest) — 2021-07-29
- 3.1.2 — 2019-05-21
- 3.1.1 — 2018-02-14
- 3.1.0 — 2018-02-05
- 3.0.0 — 2018-02-04
- 2.2.1 — 2017-11-22
- 2.2.0 — 2017-11-22
- 2.1.0 — 2017-10-16
- 2.0.4 — 2017-10-10
- 2.0.3 — 2017-10-10
- 2.0.2 — 2017-10-10
- 2.0.1 — 2017-10-02
- 2.0.0 — 2017-10-02
- 1.2.0 — 2017-08-23
- 1.1.1 — 2017-07-15
- … 3 more at https://npm.io/package/geojson-rbush/versions

## README

# GeoJSON RBush

[![Build Status](https://travis-ci.org/DenisCarriere/geojson-rbush.svg?branch=master)](https://travis-ci.org/DenisCarriere/geojson-rbush)
[![npm version](https://badge.fury.io/js/geojson-rbush.svg)](https://badge.fury.io/js/geojson-rbush)
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/DenisCarriere/geojson-rbush/master/LICENSE)

GeoJSON implementation of [RBush](https://github.com/mourner/rbush) — a high-performance JavaScript R-tree-based 2D spatial index for points and rectangles.

## Install

**npm**

```bash
$ npm install --save geojson-rbush
```

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

#### Table of Contents

-   [rbush](#rbush)
-   [insert](#insert)
-   [load](#load)
-   [remove](#remove)
-   [clear](#clear)
-   [search](#search)
-   [collides](#collides)
-   [all](#all)
-   [toJSON](#tojson)
-   [fromJSON](#fromjson)

### rbush

GeoJSON implementation of [RBush](https://github.com/mourner/rbush#rbush) spatial index.

**Parameters**

-   `maxEntries` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** defines the maximum number of entries in a tree node. 9 (used by default) is a
    reasonable choice for most applications. Higher value means faster insertion and slower search, and vice versa. (optional, default `9`)

**Examples**

```javascript
var geojsonRbush = require('geojson-rbush').default;
var tree = geojsonRbush();
```

Returns **RBush** GeoJSON RBush

### insert

[insert](https://github.com/mourner/rbush#data-format)

**Parameters**

-   `feature` **Feature** insert single GeoJSON Feature

**Examples**

```javascript
var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);
tree.insert(poly)
```

Returns **RBush** GeoJSON RBush

### load

[load](https://github.com/mourner/rbush#bulk-inserting-data)

**Parameters**

-   `features` **(FeatureCollection | [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;Feature>)** load entire GeoJSON FeatureCollection

**Examples**

```javascript
var polys = turf.polygons([
    [[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]],
    [[[-93, 32], [-83, 32], [-83, 39], [-93, 39], [-93, 32]]]
]);
tree.load(polys);
```

Returns **RBush** GeoJSON RBush

### remove

[remove](https://github.com/mourner/rbush#removing-data)

**Parameters**

-   `feature` **Feature** remove single GeoJSON Feature
-   `equals` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Pass a custom equals function to compare by value for removal.

**Examples**

```javascript
var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);

tree.remove(poly);
```

Returns **RBush** GeoJSON RBush

### clear

[clear](https://github.com/mourner/rbush#removing-data)

**Examples**

```javascript
tree.clear()
```

Returns **RBush** GeoJSON Rbush

### search

[search](https://github.com/mourner/rbush#search)

**Parameters**

-   `geojson` **(BBox | FeatureCollection | Feature)** search with GeoJSON

**Examples**

```javascript
var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);

tree.search(poly);
```

Returns **FeatureCollection** all features that intersects with the given GeoJSON.

### collides

[collides](https://github.com/mourner/rbush#collisions)

**Parameters**

-   `geojson` **(BBox | FeatureCollection | Feature)** collides with GeoJSON

**Examples**

```javascript
var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);

tree.collides(poly);
```

Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if there are any items intersecting the given GeoJSON, otherwise false.

### all

[all](https://github.com/mourner/rbush#search)

**Examples**

```javascript
tree.all()
```

Returns **FeatureCollection** all the features in RBush

### toJSON

[toJSON](https://github.com/mourner/rbush#export-and-import)

**Examples**

```javascript
var exported = tree.toJSON()
```

Returns **any** export data as JSON object

### fromJSON

[fromJSON](https://github.com/mourner/rbush#export-and-import)

**Parameters**

-   `json` **any** import previously exported data

**Examples**

```javascript
var exported = {
  "children": [
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [110, 50]
      },
      "properties": {},
      "bbox": [110, 50, 110, 50]
    }
  ],
  "height": 1,
  "leaf": true,
  "minX": 110,
  "minY": 50,
  "maxX": 110,
  "maxY": 50
}
tree.fromJSON(exported)
```

Returns **RBush** GeoJSON RBush

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