https://github.com/deniscarriere/geojson-rbush
GeoJSON implementation of RBush — a high-performance JavaScript R-tree-based 2D spatial index for points and rectangles
https://github.com/deniscarriere/geojson-rbush
algorithm computational-geometry geojson javascript r-tree spatial-index
Last synced: 2 months ago
JSON representation
GeoJSON implementation of RBush — a high-performance JavaScript R-tree-based 2D spatial index for points and rectangles
- Host: GitHub
- URL: https://github.com/deniscarriere/geojson-rbush
- Owner: DenisCarriere
- License: mit
- Created: 2017-03-20T12:14:08.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-02-28T19:19:05.000Z (about 2 years ago)
- Last Synced: 2024-04-14T19:39:24.487Z (about 1 year ago)
- Topics: algorithm, computational-geometry, geojson, javascript, r-tree, spatial-index
- Language: JavaScript
- Homepage:
- Size: 2.01 MB
- Stars: 70
- Watchers: 3
- Forks: 16
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# GeoJSON RBush
[](https://travis-ci.org/DenisCarriere/geojson-rbush)
[](https://badge.fury.io/js/geojson-rbush)
[](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
#### 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)<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