@turf/geojson-rbush 3.2.1 → 7.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018 Denis Carriere
3
+ Copyright (c) 2017 TurfJS
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
@@ -17,4 +17,4 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
17
  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
18
  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
19
  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,50 +1,182 @@
1
- # GeoJSON RBush used in TurfJS
1
+ # @turf/geojson-rbush
2
2
 
3
- This fork of geojson-rbush is configured and published for the sole purpose of importing it to [TurfJS](https://github.com/Turfjs/turf).
3
+ <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
4
4
 
5
- More information about the original library: https://github.com/DenisCarriere/geojson-rbush
5
+ ## rbush
6
6
 
7
- > This library is not intended to be used outside of TurfJS
7
+ ### insert
8
8
 
9
- [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/DenisCarriere/geojson-rbush/master/LICENSE)
9
+ [insert][1]
10
10
 
11
- GeoJSON implementation of [RBush](https://github.com/mourner/rbush) — a high-performance JavaScript R-tree-based 2D spatial index for points and rectangles.
11
+ #### Parameters
12
12
 
13
- ## Install
13
+ * `feature` **[Feature][2]** insert single GeoJSON Feature
14
14
 
15
- **npm**
15
+ #### Examples
16
16
 
17
- ```bash
18
- $ npm install --save geojson-rbush
17
+ ```javascript
18
+ var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);
19
+ tree.insert(poly)
19
20
  ```
20
21
 
21
- ## API
22
+ Returns **RBush** GeoJSON RBush
22
23
 
23
- <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
24
+ ### load
25
+
26
+ [load][3]
27
+
28
+ #### Parameters
29
+
30
+ * `features` **([FeatureCollection][4] | [Array][5]<[Feature][2]>)** load entire GeoJSON FeatureCollection
31
+
32
+ #### Examples
33
+
34
+ ```javascript
35
+ var polys = turf.polygons([
36
+ [[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]],
37
+ [[[-93, 32], [-83, 32], [-83, 39], [-93, 39], [-93, 32]]]
38
+ ]);
39
+ tree.load(polys);
40
+ ```
41
+
42
+ Returns **RBush** GeoJSON RBush
43
+
44
+ ### remove
45
+
46
+ [remove][6]
47
+
48
+ #### Parameters
49
+
50
+ * `feature` **[Feature][2]** remove single GeoJSON Feature
51
+ * `equals` **[Function][7]** Pass a custom equals function to compare by value for removal.
52
+
53
+ #### Examples
54
+
55
+ ```javascript
56
+ var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);
57
+
58
+ tree.remove(poly);
59
+ ```
60
+
61
+ Returns **RBush** GeoJSON RBush
62
+
63
+ ### clear
64
+
65
+ [clear][6]
66
+
67
+ #### Examples
68
+
69
+ ```javascript
70
+ tree.clear()
71
+ ```
72
+
73
+ Returns **RBush** GeoJSON Rbush
74
+
75
+ ### search
76
+
77
+ [search][8]
78
+
79
+ #### Parameters
80
+
81
+ * `geojson` **([BBox][9] | [FeatureCollection][4] | [Feature][2])** search with GeoJSON
82
+
83
+ #### Examples
84
+
85
+ ```javascript
86
+ var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);
87
+
88
+ tree.search(poly);
89
+ ```
90
+
91
+ Returns **[FeatureCollection][4]** all features that intersects with the given GeoJSON.
92
+
93
+ ### collides
94
+
95
+ [collides][10]
96
+
97
+ #### Parameters
98
+
99
+ * `geojson` **([BBox][9] | [FeatureCollection][4] | [Feature][2])** collides with GeoJSON
100
+
101
+ #### Examples
102
+
103
+ ```javascript
104
+ var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);
105
+
106
+ tree.collides(poly);
107
+ ```
108
+
109
+ Returns **[boolean][11]** true if there are any items intersecting the given GeoJSON, otherwise false.
24
110
 
25
- #### Table of Contents
111
+ ### all
112
+
113
+ [all][8]
114
+
115
+ #### Examples
116
+
117
+ ```javascript
118
+ tree.all()
119
+ ```
120
+
121
+ Returns **[FeatureCollection][4]** all the features in RBush
122
+
123
+ ### toJSON
124
+
125
+ [toJSON][12]
126
+
127
+ #### Examples
128
+
129
+ ```javascript
130
+ var exported = tree.toJSON()
131
+ ```
132
+
133
+ Returns **any** export data as JSON object
134
+
135
+ ### fromJSON
136
+
137
+ [fromJSON][12]
138
+
139
+ #### Parameters
140
+
141
+ * `json` **any** import previously exported data
142
+
143
+ #### Examples
144
+
145
+ ```javascript
146
+ var exported = {
147
+ "children": [
148
+ {
149
+ "type": "Feature",
150
+ "geometry": {
151
+ "type": "Point",
152
+ "coordinates": [110, 50]
153
+ },
154
+ "properties": {},
155
+ "bbox": [110, 50, 110, 50]
156
+ }
157
+ ],
158
+ "height": 1,
159
+ "leaf": true,
160
+ "minX": 110,
161
+ "minY": 50,
162
+ "maxX": 110,
163
+ "maxY": 50
164
+ }
165
+ tree.fromJSON(exported)
166
+ ```
26
167
 
27
- - [rbush](#rbush)
28
- - [insert](#insert)
29
- - [load](#load)
30
- - [remove](#remove)
31
- - [clear](#clear)
32
- - [search](#search)
33
- - [collides](#collides)
34
- - [all](#all)
35
- - [toJSON](#tojson)
36
- - [fromJSON](#fromjson)
168
+ Returns **RBush** GeoJSON RBush
37
169
 
38
- ### rbush
170
+ ## rbush
39
171
 
40
- GeoJSON implementation of [RBush](https://github.com/mourner/rbush#rbush) spatial index.
172
+ GeoJSON implementation of [RBush][13] spatial index.
41
173
 
42
- **Parameters**
174
+ ### Parameters
43
175
 
44
- - `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
176
+ * `maxEntries` **[number][14]** defines the maximum number of entries in a tree node. 9 (used by default) is a
45
177
  reasonable choice for most applications. Higher value means faster insertion and slower search, and vice versa. (optional, default `9`)
46
178
 
47
- **Examples**
179
+ ### Examples
48
180
 
49
181
  ```javascript
50
182
  var geojsonRbush = require('geojson-rbush').default;
@@ -55,13 +187,13 @@ Returns **RBush** GeoJSON RBush
55
187
 
56
188
  ### insert
57
189
 
58
- [insert](https://github.com/mourner/rbush#data-format)
190
+ [insert][1]
59
191
 
60
- **Parameters**
192
+ #### Parameters
61
193
 
62
- - `feature` **Feature** insert single GeoJSON Feature
194
+ * `feature` **[Feature][2]** insert single GeoJSON Feature
63
195
 
64
- **Examples**
196
+ #### Examples
65
197
 
66
198
  ```javascript
67
199
  var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);
@@ -72,13 +204,13 @@ Returns **RBush** GeoJSON RBush
72
204
 
73
205
  ### load
74
206
 
75
- [load](https://github.com/mourner/rbush#bulk-inserting-data)
207
+ [load][3]
76
208
 
77
- **Parameters**
209
+ #### Parameters
78
210
 
79
- - `features` **(FeatureCollection | [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;Feature>)** load entire GeoJSON FeatureCollection
211
+ * `features` **([FeatureCollection][4] | [Array][5]<[Feature][2]>)** load entire GeoJSON FeatureCollection
80
212
 
81
- **Examples**
213
+ #### Examples
82
214
 
83
215
  ```javascript
84
216
  var polys = turf.polygons([
@@ -92,14 +224,14 @@ Returns **RBush** GeoJSON RBush
92
224
 
93
225
  ### remove
94
226
 
95
- [remove](https://github.com/mourner/rbush#removing-data)
227
+ [remove][6]
96
228
 
97
- **Parameters**
229
+ #### Parameters
98
230
 
99
- - `feature` **Feature** remove single GeoJSON Feature
100
- - `equals` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Pass a custom equals function to compare by value for removal.
231
+ * `feature` **[Feature][2]** remove single GeoJSON Feature
232
+ * `equals` **[Function][7]** Pass a custom equals function to compare by value for removal.
101
233
 
102
- **Examples**
234
+ #### Examples
103
235
 
104
236
  ```javascript
105
237
  var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);
@@ -111,9 +243,9 @@ Returns **RBush** GeoJSON RBush
111
243
 
112
244
  ### clear
113
245
 
114
- [clear](https://github.com/mourner/rbush#removing-data)
246
+ [clear][6]
115
247
 
116
- **Examples**
248
+ #### Examples
117
249
 
118
250
  ```javascript
119
251
  tree.clear()
@@ -123,13 +255,13 @@ Returns **RBush** GeoJSON Rbush
123
255
 
124
256
  ### search
125
257
 
126
- [search](https://github.com/mourner/rbush#search)
258
+ [search][8]
127
259
 
128
- **Parameters**
260
+ #### Parameters
129
261
 
130
- - `geojson` **(BBox | FeatureCollection | Feature)** search with GeoJSON
262
+ * `geojson` **([BBox][9] | [FeatureCollection][4] | [Feature][2])** search with GeoJSON
131
263
 
132
- **Examples**
264
+ #### Examples
133
265
 
134
266
  ```javascript
135
267
  var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);
@@ -137,17 +269,17 @@ var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]
137
269
  tree.search(poly);
138
270
  ```
139
271
 
140
- Returns **FeatureCollection** all features that intersects with the given GeoJSON.
272
+ Returns **[FeatureCollection][4]** all features that intersects with the given GeoJSON.
141
273
 
142
274
  ### collides
143
275
 
144
- [collides](https://github.com/mourner/rbush#collisions)
276
+ [collides][10]
145
277
 
146
- **Parameters**
278
+ #### Parameters
147
279
 
148
- - `geojson` **(BBox | FeatureCollection | Feature)** collides with GeoJSON
280
+ * `geojson` **([BBox][9] | [FeatureCollection][4] | [Feature][2])** collides with GeoJSON
149
281
 
150
- **Examples**
282
+ #### Examples
151
283
 
152
284
  ```javascript
153
285
  var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);
@@ -155,25 +287,25 @@ var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]
155
287
  tree.collides(poly);
156
288
  ```
157
289
 
158
- 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.
290
+ Returns **[boolean][11]** true if there are any items intersecting the given GeoJSON, otherwise false.
159
291
 
160
292
  ### all
161
293
 
162
- [all](https://github.com/mourner/rbush#search)
294
+ [all][8]
163
295
 
164
- **Examples**
296
+ #### Examples
165
297
 
166
298
  ```javascript
167
299
  tree.all()
168
300
  ```
169
301
 
170
- Returns **FeatureCollection** all the features in RBush
302
+ Returns **[FeatureCollection][4]** all the features in RBush
171
303
 
172
304
  ### toJSON
173
305
 
174
- [toJSON](https://github.com/mourner/rbush#export-and-import)
306
+ [toJSON][12]
175
307
 
176
- **Examples**
308
+ #### Examples
177
309
 
178
310
  ```javascript
179
311
  var exported = tree.toJSON()
@@ -183,13 +315,13 @@ Returns **any** export data as JSON object
183
315
 
184
316
  ### fromJSON
185
317
 
186
- [fromJSON](https://github.com/mourner/rbush#export-and-import)
318
+ [fromJSON][12]
187
319
 
188
- **Parameters**
320
+ #### Parameters
189
321
 
190
- - `json` **any** import previously exported data
322
+ * `json` **any** import previously exported data
191
323
 
192
- **Examples**
324
+ #### Examples
193
325
 
194
326
  ```javascript
195
327
  var exported = {
@@ -215,3 +347,51 @@ tree.fromJSON(exported)
215
347
  ```
216
348
 
217
349
  Returns **RBush** GeoJSON RBush
350
+
351
+ [1]: https://github.com/mourner/rbush#data-format
352
+
353
+ [2]: https://tools.ietf.org/html/rfc7946#section-3.2
354
+
355
+ [3]: https://github.com/mourner/rbush#bulk-inserting-data
356
+
357
+ [4]: https://tools.ietf.org/html/rfc7946#section-3.3
358
+
359
+ [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
360
+
361
+ [6]: https://github.com/mourner/rbush#removing-data
362
+
363
+ [7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
364
+
365
+ [8]: https://github.com/mourner/rbush#search
366
+
367
+ [9]: https://tools.ietf.org/html/rfc7946#section-5
368
+
369
+ [10]: https://github.com/mourner/rbush#collisions
370
+
371
+ [11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
372
+
373
+ [12]: https://github.com/mourner/rbush#export-and-import
374
+
375
+ [13]: https://github.com/mourner/rbush#rbush
376
+
377
+ [14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
378
+
379
+ <!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
380
+
381
+ ---
382
+
383
+ This module is part of the [Turfjs project](https://turfjs.org/), an open source module collection dedicated to geographic algorithms. It is maintained in the [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create PRs and issues.
384
+
385
+ ### Installation
386
+
387
+ Install this single module individually:
388
+
389
+ ```sh
390
+ $ npm install @turf/geojson-rbush
391
+ ```
392
+
393
+ Or install the all-encompassing @turf/turf module that includes all modules as functions:
394
+
395
+ ```sh
396
+ $ npm install @turf/turf
397
+ ```
@@ -0,0 +1,91 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // index.js
5
+ var _rbush = require('rbush'); var _rbush2 = _interopRequireDefault(_rbush);
6
+ var _helpers = require('@turf/helpers');
7
+ var _meta = require('@turf/meta');
8
+ var _bbox = require('@turf/bbox');
9
+ function geojsonRbush(maxEntries) {
10
+ var tree = new (0, _rbush2.default)(maxEntries);
11
+ tree.insert = function(feature) {
12
+ if (feature.type !== "Feature")
13
+ throw new Error("invalid feature");
14
+ feature.bbox = feature.bbox ? feature.bbox : _bbox.bbox.call(void 0, feature);
15
+ return _rbush2.default.prototype.insert.call(this, feature);
16
+ };
17
+ tree.load = function(features) {
18
+ var load = [];
19
+ if (Array.isArray(features)) {
20
+ features.forEach(function(feature) {
21
+ if (feature.type !== "Feature")
22
+ throw new Error("invalid features");
23
+ feature.bbox = feature.bbox ? feature.bbox : _bbox.bbox.call(void 0, feature);
24
+ load.push(feature);
25
+ });
26
+ } else {
27
+ _meta.featureEach.call(void 0, features, function(feature) {
28
+ if (feature.type !== "Feature")
29
+ throw new Error("invalid features");
30
+ feature.bbox = feature.bbox ? feature.bbox : _bbox.bbox.call(void 0, feature);
31
+ load.push(feature);
32
+ });
33
+ }
34
+ return _rbush2.default.prototype.load.call(this, load);
35
+ };
36
+ tree.remove = function(feature, equals) {
37
+ if (feature.type !== "Feature")
38
+ throw new Error("invalid feature");
39
+ feature.bbox = feature.bbox ? feature.bbox : _bbox.bbox.call(void 0, feature);
40
+ return _rbush2.default.prototype.remove.call(this, feature, equals);
41
+ };
42
+ tree.clear = function() {
43
+ return _rbush2.default.prototype.clear.call(this);
44
+ };
45
+ tree.search = function(geojson) {
46
+ var features = _rbush2.default.prototype.search.call(this, this.toBBox(geojson));
47
+ return _helpers.featureCollection.call(void 0, features);
48
+ };
49
+ tree.collides = function(geojson) {
50
+ return _rbush2.default.prototype.collides.call(this, this.toBBox(geojson));
51
+ };
52
+ tree.all = function() {
53
+ var features = _rbush2.default.prototype.all.call(this);
54
+ return _helpers.featureCollection.call(void 0, features);
55
+ };
56
+ tree.toJSON = function() {
57
+ return _rbush2.default.prototype.toJSON.call(this);
58
+ };
59
+ tree.fromJSON = function(json) {
60
+ return _rbush2.default.prototype.fromJSON.call(this, json);
61
+ };
62
+ tree.toBBox = function(geojson) {
63
+ var bbox;
64
+ if (geojson.bbox)
65
+ bbox = geojson.bbox;
66
+ else if (Array.isArray(geojson) && geojson.length === 4)
67
+ bbox = geojson;
68
+ else if (Array.isArray(geojson) && geojson.length === 6)
69
+ bbox = [geojson[0], geojson[1], geojson[3], geojson[4]];
70
+ else if (geojson.type === "Feature")
71
+ bbox = _bbox.bbox.call(void 0, geojson);
72
+ else if (geojson.type === "FeatureCollection")
73
+ bbox = _bbox.bbox.call(void 0, geojson);
74
+ else
75
+ throw new Error("invalid geojson");
76
+ return {
77
+ minX: bbox[0],
78
+ minY: bbox[1],
79
+ maxX: bbox[2],
80
+ maxY: bbox[3]
81
+ };
82
+ };
83
+ return tree;
84
+ }
85
+ __name(geojsonRbush, "geojsonRbush");
86
+ var turf_geojson_rbush_default = geojsonRbush;
87
+
88
+
89
+
90
+ exports.default = turf_geojson_rbush_default; exports.geojsonRbush = geojsonRbush;
91
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.js"],"names":[],"mappings":";;;;AAAA,OAAO,WAAW;AAClB,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B,SAAS,QAAQ,gBAAgB;AAiBjC,SAAS,aAAa,YAAY;AAChC,MAAI,OAAO,IAAI,MAAM,UAAU;AAY/B,OAAK,SAAS,SAAU,SAAS;AAC/B,QAAI,QAAQ,SAAS;AAAW,YAAM,IAAI,MAAM,iBAAiB;AACjE,YAAQ,OAAO,QAAQ,OAAO,QAAQ,OAAO,SAAS,OAAO;AAC7D,WAAO,MAAM,UAAU,OAAO,KAAK,MAAM,OAAO;AAAA,EAClD;AAeA,OAAK,OAAO,SAAU,UAAU;AAC9B,QAAI,OAAO,CAAC;AAEZ,QAAI,MAAM,QAAQ,QAAQ,GAAG;AAC3B,eAAS,QAAQ,SAAU,SAAS;AAClC,YAAI,QAAQ,SAAS;AAAW,gBAAM,IAAI,MAAM,kBAAkB;AAClE,gBAAQ,OAAO,QAAQ,OAAO,QAAQ,OAAO,SAAS,OAAO;AAC7D,aAAK,KAAK,OAAO;AAAA,MACnB,CAAC;AAAA,IACH,OAAO;AAEL,kBAAY,UAAU,SAAU,SAAS;AACvC,YAAI,QAAQ,SAAS;AAAW,gBAAM,IAAI,MAAM,kBAAkB;AAClE,gBAAQ,OAAO,QAAQ,OAAO,QAAQ,OAAO,SAAS,OAAO;AAC7D,aAAK,KAAK,OAAO;AAAA,MACnB,CAAC;AAAA,IACH;AACA,WAAO,MAAM,UAAU,KAAK,KAAK,MAAM,IAAI;AAAA,EAC7C;AAcA,OAAK,SAAS,SAAU,SAAS,QAAQ;AACvC,QAAI,QAAQ,SAAS;AAAW,YAAM,IAAI,MAAM,iBAAiB;AACjE,YAAQ,OAAO,QAAQ,OAAO,QAAQ,OAAO,SAAS,OAAO;AAC7D,WAAO,MAAM,UAAU,OAAO,KAAK,MAAM,SAAS,MAAM;AAAA,EAC1D;AAUA,OAAK,QAAQ,WAAY;AACvB,WAAO,MAAM,UAAU,MAAM,KAAK,IAAI;AAAA,EACxC;AAaA,OAAK,SAAS,SAAU,SAAS;AAC/B,QAAI,WAAW,MAAM,UAAU,OAAO,KAAK,MAAM,KAAK,OAAO,OAAO,CAAC;AACrE,WAAO,kBAAkB,QAAQ;AAAA,EACnC;AAaA,OAAK,WAAW,SAAU,SAAS;AACjC,WAAO,MAAM,UAAU,SAAS,KAAK,MAAM,KAAK,OAAO,OAAO,CAAC;AAAA,EACjE;AAUA,OAAK,MAAM,WAAY;AACrB,QAAI,WAAW,MAAM,UAAU,IAAI,KAAK,IAAI;AAC5C,WAAO,kBAAkB,QAAQ;AAAA,EACnC;AAUA,OAAK,SAAS,WAAY;AACxB,WAAO,MAAM,UAAU,OAAO,KAAK,IAAI;AAAA,EACzC;AA8BA,OAAK,WAAW,SAAU,MAAM;AAC9B,WAAO,MAAM,UAAU,SAAS,KAAK,MAAM,IAAI;AAAA,EACjD;AAUA,OAAK,SAAS,SAAU,SAAS;AAC/B,QAAI;AACJ,QAAI,QAAQ;AAAM,aAAO,QAAQ;AAAA,aACxB,MAAM,QAAQ,OAAO,KAAK,QAAQ,WAAW;AAAG,aAAO;AAAA,aACvD,MAAM,QAAQ,OAAO,KAAK,QAAQ,WAAW;AACpD,aAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC,GAAG,QAAQ,CAAC,GAAG,QAAQ,CAAC,CAAC;AAAA,aAC/C,QAAQ,SAAS;AAAW,aAAO,SAAS,OAAO;AAAA,aACnD,QAAQ,SAAS;AAAqB,aAAO,SAAS,OAAO;AAAA;AACjE,YAAM,IAAI,MAAM,iBAAiB;AAEtC,WAAO;AAAA,MACL,MAAM,KAAK,CAAC;AAAA,MACZ,MAAM,KAAK,CAAC;AAAA,MACZ,MAAM,KAAK,CAAC;AAAA,MACZ,MAAM,KAAK,CAAC;AAAA,IACd;AAAA,EACF;AACA,SAAO;AACT;AApMS;AAuMT,IAAO,6BAAQ","sourcesContent":["import rbush from \"rbush\";\nimport { featureCollection } from \"@turf/helpers\";\nimport { featureEach } from \"@turf/meta\";\nimport { bbox as turfBBox } from \"@turf/bbox\";\n\n/**\n * @module rbush\n */\n\n/**\n * GeoJSON implementation of [RBush](https://github.com/mourner/rbush#rbush) spatial index.\n *\n * @name rbush\n * @param {number} [maxEntries=9] defines the maximum number of entries in a tree node. 9 (used by default) is a\n * reasonable choice for most applications. Higher value means faster insertion and slower search, and vice versa.\n * @returns {RBush} GeoJSON RBush\n * @example\n * var geojsonRbush = require('geojson-rbush').default;\n * var tree = geojsonRbush();\n */\nfunction geojsonRbush(maxEntries) {\n var tree = new rbush(maxEntries);\n\n /**\n * [insert](https://github.com/mourner/rbush#data-format)\n *\n * @memberof rbush\n * @param {Feature} feature insert single GeoJSON Feature\n * @returns {RBush} GeoJSON RBush\n * @example\n * var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);\n * tree.insert(poly)\n */\n tree.insert = function (feature) {\n if (feature.type !== \"Feature\") throw new Error(\"invalid feature\");\n feature.bbox = feature.bbox ? feature.bbox : turfBBox(feature);\n return rbush.prototype.insert.call(this, feature);\n };\n\n /**\n * [load](https://github.com/mourner/rbush#bulk-inserting-data)\n *\n * @memberof rbush\n * @param {FeatureCollection|Array<Feature>} features load entire GeoJSON FeatureCollection\n * @returns {RBush} GeoJSON RBush\n * @example\n * var polys = turf.polygons([\n * [[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]],\n * [[[-93, 32], [-83, 32], [-83, 39], [-93, 39], [-93, 32]]]\n * ]);\n * tree.load(polys);\n */\n tree.load = function (features) {\n var load = [];\n // Load an Array of Features\n if (Array.isArray(features)) {\n features.forEach(function (feature) {\n if (feature.type !== \"Feature\") throw new Error(\"invalid features\");\n feature.bbox = feature.bbox ? feature.bbox : turfBBox(feature);\n load.push(feature);\n });\n } else {\n // Load a FeatureCollection\n featureEach(features, function (feature) {\n if (feature.type !== \"Feature\") throw new Error(\"invalid features\");\n feature.bbox = feature.bbox ? feature.bbox : turfBBox(feature);\n load.push(feature);\n });\n }\n return rbush.prototype.load.call(this, load);\n };\n\n /**\n * [remove](https://github.com/mourner/rbush#removing-data)\n *\n * @memberof rbush\n * @param {Feature} feature remove single GeoJSON Feature\n * @param {Function} equals Pass a custom equals function to compare by value for removal.\n * @returns {RBush} GeoJSON RBush\n * @example\n * var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);\n *\n * tree.remove(poly);\n */\n tree.remove = function (feature, equals) {\n if (feature.type !== \"Feature\") throw new Error(\"invalid feature\");\n feature.bbox = feature.bbox ? feature.bbox : turfBBox(feature);\n return rbush.prototype.remove.call(this, feature, equals);\n };\n\n /**\n * [clear](https://github.com/mourner/rbush#removing-data)\n *\n * @memberof rbush\n * @returns {RBush} GeoJSON Rbush\n * @example\n * tree.clear()\n */\n tree.clear = function () {\n return rbush.prototype.clear.call(this);\n };\n\n /**\n * [search](https://github.com/mourner/rbush#search)\n *\n * @memberof rbush\n * @param {BBox|FeatureCollection|Feature} geojson search with GeoJSON\n * @returns {FeatureCollection} all features that intersects with the given GeoJSON.\n * @example\n * var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);\n *\n * tree.search(poly);\n */\n tree.search = function (geojson) {\n var features = rbush.prototype.search.call(this, this.toBBox(geojson));\n return featureCollection(features);\n };\n\n /**\n * [collides](https://github.com/mourner/rbush#collisions)\n *\n * @memberof rbush\n * @param {BBox|FeatureCollection|Feature} geojson collides with GeoJSON\n * @returns {boolean} true if there are any items intersecting the given GeoJSON, otherwise false.\n * @example\n * var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);\n *\n * tree.collides(poly);\n */\n tree.collides = function (geojson) {\n return rbush.prototype.collides.call(this, this.toBBox(geojson));\n };\n\n /**\n * [all](https://github.com/mourner/rbush#search)\n *\n * @memberof rbush\n * @returns {FeatureCollection} all the features in RBush\n * @example\n * tree.all()\n */\n tree.all = function () {\n var features = rbush.prototype.all.call(this);\n return featureCollection(features);\n };\n\n /**\n * [toJSON](https://github.com/mourner/rbush#export-and-import)\n *\n * @memberof rbush\n * @returns {any} export data as JSON object\n * @example\n * var exported = tree.toJSON()\n */\n tree.toJSON = function () {\n return rbush.prototype.toJSON.call(this);\n };\n\n /**\n * [fromJSON](https://github.com/mourner/rbush#export-and-import)\n *\n * @memberof rbush\n * @param {any} json import previously exported data\n * @returns {RBush} GeoJSON RBush\n * @example\n * var exported = {\n * \"children\": [\n * {\n * \"type\": \"Feature\",\n * \"geometry\": {\n * \"type\": \"Point\",\n * \"coordinates\": [110, 50]\n * },\n * \"properties\": {},\n * \"bbox\": [110, 50, 110, 50]\n * }\n * ],\n * \"height\": 1,\n * \"leaf\": true,\n * \"minX\": 110,\n * \"minY\": 50,\n * \"maxX\": 110,\n * \"maxY\": 50\n * }\n * tree.fromJSON(exported)\n */\n tree.fromJSON = function (json) {\n return rbush.prototype.fromJSON.call(this, json);\n };\n\n /**\n * Converts GeoJSON to {minX, minY, maxX, maxY} schema\n *\n * @memberof rbush\n * @private\n * @param {BBox|FeatureCollection|Feature} geojson feature(s) to retrieve BBox from\n * @returns {Object} converted to {minX, minY, maxX, maxY}\n */\n tree.toBBox = function (geojson) {\n var bbox;\n if (geojson.bbox) bbox = geojson.bbox;\n else if (Array.isArray(geojson) && geojson.length === 4) bbox = geojson;\n else if (Array.isArray(geojson) && geojson.length === 6)\n bbox = [geojson[0], geojson[1], geojson[3], geojson[4]];\n else if (geojson.type === \"Feature\") bbox = turfBBox(geojson);\n else if (geojson.type === \"FeatureCollection\") bbox = turfBBox(geojson);\n else throw new Error(\"invalid geojson\");\n\n return {\n minX: bbox[0],\n minY: bbox[1],\n maxX: bbox[2],\n maxY: bbox[3],\n };\n };\n return tree;\n}\n\nexport { geojsonRbush };\nexport default geojsonRbush;\n"]}
@@ -0,0 +1,26 @@
1
+ import { Geometry, GeoJsonProperties, Feature, FeatureCollection, BBox } from 'geojson';
2
+
3
+ declare class RBush<G extends Geometry, P extends GeoJsonProperties> {
4
+ insert(feature: Feature<G, P>): RBush<G, P>;
5
+ load(features: FeatureCollection<G, P> | Feature<G, P>[]): RBush<G, P>;
6
+ remove(
7
+ feature: Feature<G, P>,
8
+ equals?: (a: Feature<G, P>, b: Feature<G, P>) => boolean
9
+ ): RBush<G, P>;
10
+ clear(): RBush<G, P>;
11
+ search(geojson: Feature | FeatureCollection | BBox): FeatureCollection<G, P>;
12
+ all(): FeatureCollection<any>;
13
+ collides(geosjon: Feature | FeatureCollection | BBox): boolean;
14
+ toJSON(): any;
15
+ fromJSON(data: any): RBush<G, P>;
16
+ }
17
+
18
+ /**
19
+ * https://github.com/mourner/rbush
20
+ */
21
+ declare function geojsonRbush<
22
+ G extends Geometry = Geometry,
23
+ P extends GeoJsonProperties = GeoJsonProperties,
24
+ >(maxEntries?: number): RBush<G, P>;
25
+
26
+ export { geojsonRbush as default, geojsonRbush };
@@ -0,0 +1,26 @@
1
+ import { Geometry, GeoJsonProperties, Feature, FeatureCollection, BBox } from 'geojson';
2
+
3
+ declare class RBush<G extends Geometry, P extends GeoJsonProperties> {
4
+ insert(feature: Feature<G, P>): RBush<G, P>;
5
+ load(features: FeatureCollection<G, P> | Feature<G, P>[]): RBush<G, P>;
6
+ remove(
7
+ feature: Feature<G, P>,
8
+ equals?: (a: Feature<G, P>, b: Feature<G, P>) => boolean
9
+ ): RBush<G, P>;
10
+ clear(): RBush<G, P>;
11
+ search(geojson: Feature | FeatureCollection | BBox): FeatureCollection<G, P>;
12
+ all(): FeatureCollection<any>;
13
+ collides(geosjon: Feature | FeatureCollection | BBox): boolean;
14
+ toJSON(): any;
15
+ fromJSON(data: any): RBush<G, P>;
16
+ }
17
+
18
+ /**
19
+ * https://github.com/mourner/rbush
20
+ */
21
+ declare function geojsonRbush<
22
+ G extends Geometry = Geometry,
23
+ P extends GeoJsonProperties = GeoJsonProperties,
24
+ >(maxEntries?: number): RBush<G, P>;
25
+
26
+ export { geojsonRbush as default, geojsonRbush };
@@ -0,0 +1,91 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // index.js
5
+ import rbush from "rbush";
6
+ import { featureCollection } from "@turf/helpers";
7
+ import { featureEach } from "@turf/meta";
8
+ import { bbox as turfBBox } from "@turf/bbox";
9
+ function geojsonRbush(maxEntries) {
10
+ var tree = new rbush(maxEntries);
11
+ tree.insert = function(feature) {
12
+ if (feature.type !== "Feature")
13
+ throw new Error("invalid feature");
14
+ feature.bbox = feature.bbox ? feature.bbox : turfBBox(feature);
15
+ return rbush.prototype.insert.call(this, feature);
16
+ };
17
+ tree.load = function(features) {
18
+ var load = [];
19
+ if (Array.isArray(features)) {
20
+ features.forEach(function(feature) {
21
+ if (feature.type !== "Feature")
22
+ throw new Error("invalid features");
23
+ feature.bbox = feature.bbox ? feature.bbox : turfBBox(feature);
24
+ load.push(feature);
25
+ });
26
+ } else {
27
+ featureEach(features, function(feature) {
28
+ if (feature.type !== "Feature")
29
+ throw new Error("invalid features");
30
+ feature.bbox = feature.bbox ? feature.bbox : turfBBox(feature);
31
+ load.push(feature);
32
+ });
33
+ }
34
+ return rbush.prototype.load.call(this, load);
35
+ };
36
+ tree.remove = function(feature, equals) {
37
+ if (feature.type !== "Feature")
38
+ throw new Error("invalid feature");
39
+ feature.bbox = feature.bbox ? feature.bbox : turfBBox(feature);
40
+ return rbush.prototype.remove.call(this, feature, equals);
41
+ };
42
+ tree.clear = function() {
43
+ return rbush.prototype.clear.call(this);
44
+ };
45
+ tree.search = function(geojson) {
46
+ var features = rbush.prototype.search.call(this, this.toBBox(geojson));
47
+ return featureCollection(features);
48
+ };
49
+ tree.collides = function(geojson) {
50
+ return rbush.prototype.collides.call(this, this.toBBox(geojson));
51
+ };
52
+ tree.all = function() {
53
+ var features = rbush.prototype.all.call(this);
54
+ return featureCollection(features);
55
+ };
56
+ tree.toJSON = function() {
57
+ return rbush.prototype.toJSON.call(this);
58
+ };
59
+ tree.fromJSON = function(json) {
60
+ return rbush.prototype.fromJSON.call(this, json);
61
+ };
62
+ tree.toBBox = function(geojson) {
63
+ var bbox;
64
+ if (geojson.bbox)
65
+ bbox = geojson.bbox;
66
+ else if (Array.isArray(geojson) && geojson.length === 4)
67
+ bbox = geojson;
68
+ else if (Array.isArray(geojson) && geojson.length === 6)
69
+ bbox = [geojson[0], geojson[1], geojson[3], geojson[4]];
70
+ else if (geojson.type === "Feature")
71
+ bbox = turfBBox(geojson);
72
+ else if (geojson.type === "FeatureCollection")
73
+ bbox = turfBBox(geojson);
74
+ else
75
+ throw new Error("invalid geojson");
76
+ return {
77
+ minX: bbox[0],
78
+ minY: bbox[1],
79
+ maxX: bbox[2],
80
+ maxY: bbox[3]
81
+ };
82
+ };
83
+ return tree;
84
+ }
85
+ __name(geojsonRbush, "geojsonRbush");
86
+ var turf_geojson_rbush_default = geojsonRbush;
87
+ export {
88
+ turf_geojson_rbush_default as default,
89
+ geojsonRbush
90
+ };
91
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.js"],"sourcesContent":["import rbush from \"rbush\";\nimport { featureCollection } from \"@turf/helpers\";\nimport { featureEach } from \"@turf/meta\";\nimport { bbox as turfBBox } from \"@turf/bbox\";\n\n/**\n * @module rbush\n */\n\n/**\n * GeoJSON implementation of [RBush](https://github.com/mourner/rbush#rbush) spatial index.\n *\n * @name rbush\n * @param {number} [maxEntries=9] defines the maximum number of entries in a tree node. 9 (used by default) is a\n * reasonable choice for most applications. Higher value means faster insertion and slower search, and vice versa.\n * @returns {RBush} GeoJSON RBush\n * @example\n * var geojsonRbush = require('geojson-rbush').default;\n * var tree = geojsonRbush();\n */\nfunction geojsonRbush(maxEntries) {\n var tree = new rbush(maxEntries);\n\n /**\n * [insert](https://github.com/mourner/rbush#data-format)\n *\n * @memberof rbush\n * @param {Feature} feature insert single GeoJSON Feature\n * @returns {RBush} GeoJSON RBush\n * @example\n * var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);\n * tree.insert(poly)\n */\n tree.insert = function (feature) {\n if (feature.type !== \"Feature\") throw new Error(\"invalid feature\");\n feature.bbox = feature.bbox ? feature.bbox : turfBBox(feature);\n return rbush.prototype.insert.call(this, feature);\n };\n\n /**\n * [load](https://github.com/mourner/rbush#bulk-inserting-data)\n *\n * @memberof rbush\n * @param {FeatureCollection|Array<Feature>} features load entire GeoJSON FeatureCollection\n * @returns {RBush} GeoJSON RBush\n * @example\n * var polys = turf.polygons([\n * [[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]],\n * [[[-93, 32], [-83, 32], [-83, 39], [-93, 39], [-93, 32]]]\n * ]);\n * tree.load(polys);\n */\n tree.load = function (features) {\n var load = [];\n // Load an Array of Features\n if (Array.isArray(features)) {\n features.forEach(function (feature) {\n if (feature.type !== \"Feature\") throw new Error(\"invalid features\");\n feature.bbox = feature.bbox ? feature.bbox : turfBBox(feature);\n load.push(feature);\n });\n } else {\n // Load a FeatureCollection\n featureEach(features, function (feature) {\n if (feature.type !== \"Feature\") throw new Error(\"invalid features\");\n feature.bbox = feature.bbox ? feature.bbox : turfBBox(feature);\n load.push(feature);\n });\n }\n return rbush.prototype.load.call(this, load);\n };\n\n /**\n * [remove](https://github.com/mourner/rbush#removing-data)\n *\n * @memberof rbush\n * @param {Feature} feature remove single GeoJSON Feature\n * @param {Function} equals Pass a custom equals function to compare by value for removal.\n * @returns {RBush} GeoJSON RBush\n * @example\n * var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);\n *\n * tree.remove(poly);\n */\n tree.remove = function (feature, equals) {\n if (feature.type !== \"Feature\") throw new Error(\"invalid feature\");\n feature.bbox = feature.bbox ? feature.bbox : turfBBox(feature);\n return rbush.prototype.remove.call(this, feature, equals);\n };\n\n /**\n * [clear](https://github.com/mourner/rbush#removing-data)\n *\n * @memberof rbush\n * @returns {RBush} GeoJSON Rbush\n * @example\n * tree.clear()\n */\n tree.clear = function () {\n return rbush.prototype.clear.call(this);\n };\n\n /**\n * [search](https://github.com/mourner/rbush#search)\n *\n * @memberof rbush\n * @param {BBox|FeatureCollection|Feature} geojson search with GeoJSON\n * @returns {FeatureCollection} all features that intersects with the given GeoJSON.\n * @example\n * var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);\n *\n * tree.search(poly);\n */\n tree.search = function (geojson) {\n var features = rbush.prototype.search.call(this, this.toBBox(geojson));\n return featureCollection(features);\n };\n\n /**\n * [collides](https://github.com/mourner/rbush#collisions)\n *\n * @memberof rbush\n * @param {BBox|FeatureCollection|Feature} geojson collides with GeoJSON\n * @returns {boolean} true if there are any items intersecting the given GeoJSON, otherwise false.\n * @example\n * var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);\n *\n * tree.collides(poly);\n */\n tree.collides = function (geojson) {\n return rbush.prototype.collides.call(this, this.toBBox(geojson));\n };\n\n /**\n * [all](https://github.com/mourner/rbush#search)\n *\n * @memberof rbush\n * @returns {FeatureCollection} all the features in RBush\n * @example\n * tree.all()\n */\n tree.all = function () {\n var features = rbush.prototype.all.call(this);\n return featureCollection(features);\n };\n\n /**\n * [toJSON](https://github.com/mourner/rbush#export-and-import)\n *\n * @memberof rbush\n * @returns {any} export data as JSON object\n * @example\n * var exported = tree.toJSON()\n */\n tree.toJSON = function () {\n return rbush.prototype.toJSON.call(this);\n };\n\n /**\n * [fromJSON](https://github.com/mourner/rbush#export-and-import)\n *\n * @memberof rbush\n * @param {any} json import previously exported data\n * @returns {RBush} GeoJSON RBush\n * @example\n * var exported = {\n * \"children\": [\n * {\n * \"type\": \"Feature\",\n * \"geometry\": {\n * \"type\": \"Point\",\n * \"coordinates\": [110, 50]\n * },\n * \"properties\": {},\n * \"bbox\": [110, 50, 110, 50]\n * }\n * ],\n * \"height\": 1,\n * \"leaf\": true,\n * \"minX\": 110,\n * \"minY\": 50,\n * \"maxX\": 110,\n * \"maxY\": 50\n * }\n * tree.fromJSON(exported)\n */\n tree.fromJSON = function (json) {\n return rbush.prototype.fromJSON.call(this, json);\n };\n\n /**\n * Converts GeoJSON to {minX, minY, maxX, maxY} schema\n *\n * @memberof rbush\n * @private\n * @param {BBox|FeatureCollection|Feature} geojson feature(s) to retrieve BBox from\n * @returns {Object} converted to {minX, minY, maxX, maxY}\n */\n tree.toBBox = function (geojson) {\n var bbox;\n if (geojson.bbox) bbox = geojson.bbox;\n else if (Array.isArray(geojson) && geojson.length === 4) bbox = geojson;\n else if (Array.isArray(geojson) && geojson.length === 6)\n bbox = [geojson[0], geojson[1], geojson[3], geojson[4]];\n else if (geojson.type === \"Feature\") bbox = turfBBox(geojson);\n else if (geojson.type === \"FeatureCollection\") bbox = turfBBox(geojson);\n else throw new Error(\"invalid geojson\");\n\n return {\n minX: bbox[0],\n minY: bbox[1],\n maxX: bbox[2],\n maxY: bbox[3],\n };\n };\n return tree;\n}\n\nexport { geojsonRbush };\nexport default geojsonRbush;\n"],"mappings":";;;;AAAA,OAAO,WAAW;AAClB,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B,SAAS,QAAQ,gBAAgB;AAiBjC,SAAS,aAAa,YAAY;AAChC,MAAI,OAAO,IAAI,MAAM,UAAU;AAY/B,OAAK,SAAS,SAAU,SAAS;AAC/B,QAAI,QAAQ,SAAS;AAAW,YAAM,IAAI,MAAM,iBAAiB;AACjE,YAAQ,OAAO,QAAQ,OAAO,QAAQ,OAAO,SAAS,OAAO;AAC7D,WAAO,MAAM,UAAU,OAAO,KAAK,MAAM,OAAO;AAAA,EAClD;AAeA,OAAK,OAAO,SAAU,UAAU;AAC9B,QAAI,OAAO,CAAC;AAEZ,QAAI,MAAM,QAAQ,QAAQ,GAAG;AAC3B,eAAS,QAAQ,SAAU,SAAS;AAClC,YAAI,QAAQ,SAAS;AAAW,gBAAM,IAAI,MAAM,kBAAkB;AAClE,gBAAQ,OAAO,QAAQ,OAAO,QAAQ,OAAO,SAAS,OAAO;AAC7D,aAAK,KAAK,OAAO;AAAA,MACnB,CAAC;AAAA,IACH,OAAO;AAEL,kBAAY,UAAU,SAAU,SAAS;AACvC,YAAI,QAAQ,SAAS;AAAW,gBAAM,IAAI,MAAM,kBAAkB;AAClE,gBAAQ,OAAO,QAAQ,OAAO,QAAQ,OAAO,SAAS,OAAO;AAC7D,aAAK,KAAK,OAAO;AAAA,MACnB,CAAC;AAAA,IACH;AACA,WAAO,MAAM,UAAU,KAAK,KAAK,MAAM,IAAI;AAAA,EAC7C;AAcA,OAAK,SAAS,SAAU,SAAS,QAAQ;AACvC,QAAI,QAAQ,SAAS;AAAW,YAAM,IAAI,MAAM,iBAAiB;AACjE,YAAQ,OAAO,QAAQ,OAAO,QAAQ,OAAO,SAAS,OAAO;AAC7D,WAAO,MAAM,UAAU,OAAO,KAAK,MAAM,SAAS,MAAM;AAAA,EAC1D;AAUA,OAAK,QAAQ,WAAY;AACvB,WAAO,MAAM,UAAU,MAAM,KAAK,IAAI;AAAA,EACxC;AAaA,OAAK,SAAS,SAAU,SAAS;AAC/B,QAAI,WAAW,MAAM,UAAU,OAAO,KAAK,MAAM,KAAK,OAAO,OAAO,CAAC;AACrE,WAAO,kBAAkB,QAAQ;AAAA,EACnC;AAaA,OAAK,WAAW,SAAU,SAAS;AACjC,WAAO,MAAM,UAAU,SAAS,KAAK,MAAM,KAAK,OAAO,OAAO,CAAC;AAAA,EACjE;AAUA,OAAK,MAAM,WAAY;AACrB,QAAI,WAAW,MAAM,UAAU,IAAI,KAAK,IAAI;AAC5C,WAAO,kBAAkB,QAAQ;AAAA,EACnC;AAUA,OAAK,SAAS,WAAY;AACxB,WAAO,MAAM,UAAU,OAAO,KAAK,IAAI;AAAA,EACzC;AA8BA,OAAK,WAAW,SAAU,MAAM;AAC9B,WAAO,MAAM,UAAU,SAAS,KAAK,MAAM,IAAI;AAAA,EACjD;AAUA,OAAK,SAAS,SAAU,SAAS;AAC/B,QAAI;AACJ,QAAI,QAAQ;AAAM,aAAO,QAAQ;AAAA,aACxB,MAAM,QAAQ,OAAO,KAAK,QAAQ,WAAW;AAAG,aAAO;AAAA,aACvD,MAAM,QAAQ,OAAO,KAAK,QAAQ,WAAW;AACpD,aAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC,GAAG,QAAQ,CAAC,GAAG,QAAQ,CAAC,CAAC;AAAA,aAC/C,QAAQ,SAAS;AAAW,aAAO,SAAS,OAAO;AAAA,aACnD,QAAQ,SAAS;AAAqB,aAAO,SAAS,OAAO;AAAA;AACjE,YAAM,IAAI,MAAM,iBAAiB;AAEtC,WAAO;AAAA,MACL,MAAM,KAAK,CAAC;AAAA,MACZ,MAAM,KAAK,CAAC;AAAA,MACZ,MAAM,KAAK,CAAC;AAAA,MACZ,MAAM,KAAK,CAAC;AAAA,IACd;AAAA,EACF;AACA,SAAO;AACT;AApMS;AAuMT,IAAO,6BAAQ;","names":[]}
package/index.d.ts CHANGED
@@ -1,19 +1,33 @@
1
- import { BBox, Feature, FeatureCollection, Geometry, GeoJsonProperties } from 'geojson'
1
+ import {
2
+ BBox,
3
+ Feature,
4
+ FeatureCollection,
5
+ Geometry,
6
+ GeoJsonProperties,
7
+ } from "geojson";
2
8
 
3
9
  declare class RBush<G extends Geometry, P extends GeoJsonProperties> {
4
- insert(feature: Feature<G, P>): RBush<G, P>;
5
- load(features: FeatureCollection<G, P> | Feature<G, P>[]): RBush<G, P>;
6
- remove(feature: Feature<G, P>, equals?: (a: Feature<G, P>, b: Feature<G, P>) => boolean): RBush<G, P>;
7
- clear(): RBush<G, P>;
8
- search(geojson: Feature | FeatureCollection | BBox): FeatureCollection<G, P>;
9
- all(): FeatureCollection<any>;
10
- collides(geosjon: Feature | FeatureCollection | BBox): boolean;
11
- toJSON(): any;
12
- fromJSON(data: any): RBush<G, P>;
10
+ insert(feature: Feature<G, P>): RBush<G, P>;
11
+ load(features: FeatureCollection<G, P> | Feature<G, P>[]): RBush<G, P>;
12
+ remove(
13
+ feature: Feature<G, P>,
14
+ equals?: (a: Feature<G, P>, b: Feature<G, P>) => boolean
15
+ ): RBush<G, P>;
16
+ clear(): RBush<G, P>;
17
+ search(geojson: Feature | FeatureCollection | BBox): FeatureCollection<G, P>;
18
+ all(): FeatureCollection<any>;
19
+ collides(geosjon: Feature | FeatureCollection | BBox): boolean;
20
+ toJSON(): any;
21
+ fromJSON(data: any): RBush<G, P>;
13
22
  }
14
23
 
15
24
  /**
16
25
  * https://github.com/mourner/rbush
17
26
  */
18
- export default function rbush<G extends Geometry = Geometry, P = GeoJsonProperties>(maxEntries?: number): RBush<G, P>;
27
+ declare function geojsonRbush<
28
+ G extends Geometry = Geometry,
29
+ P extends GeoJsonProperties = GeoJsonProperties,
30
+ >(maxEntries?: number): RBush<G, P>;
19
31
 
32
+ export { geojsonRbush };
33
+ export default geojsonRbush;
package/package.json CHANGED
@@ -1,18 +1,25 @@
1
1
  {
2
2
  "name": "@turf/geojson-rbush",
3
- "version": "3.2.1",
3
+ "version": "7.0.0-alpha.0+135b898",
4
4
  "description": "GeoJSON implementation of RBush",
5
- "main": "index",
6
- "types": "index.d.ts",
7
- "files": [
8
- "index.js",
9
- "index.d.ts"
5
+ "author": "Turf Authors",
6
+ "contributors": [
7
+ "Vladimir Agafonkin <@mourner>",
8
+ "Denis Carriere <@DenisCarriere>",
9
+ "Jordan Rousseau <@jvrousseau>"
10
10
  ],
11
- "scripts": {
12
- "pretest": "tsc types.ts",
13
- "test": "node test.js --coverage",
14
- "bench": "node bench.js",
15
- "docs": "documentation readme index.js --section=API"
11
+ "license": "MIT",
12
+ "bugs": {
13
+ "url": "https://github.com/Turfjs/turf/issues"
14
+ },
15
+ "homepage": "https://github.com/Turfjs/turf",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git://github.com/Turfjs/turf.git"
19
+ },
20
+ "funding": "https://opencollective.com/turf",
21
+ "publishConfig": {
22
+ "access": "public"
16
23
  },
17
24
  "keywords": [
18
25
  "geojson",
@@ -21,30 +28,54 @@
21
28
  "spatial",
22
29
  "rbush"
23
30
  ],
24
- "author": "Denis Carriere <@DenisCarriere>",
25
- "contributors": [
26
- "Vladimir Agafonkin <@mourner>",
27
- "Denis Carriere <@DenisCarriere>",
28
- "Jordan Rousseau <@jvrousseau>"
31
+ "type": "commonjs",
32
+ "main": "dist/cjs/index.cjs",
33
+ "module": "dist/esm/index.mjs",
34
+ "types": "dist/cjs/index.d.ts",
35
+ "exports": {
36
+ "./package.json": "./package.json",
37
+ ".": {
38
+ "import": {
39
+ "types": "./dist/esm/index.d.mts",
40
+ "default": "./dist/esm/index.mjs"
41
+ },
42
+ "require": {
43
+ "types": "./dist/cjs/index.d.ts",
44
+ "default": "./dist/cjs/index.cjs"
45
+ }
46
+ }
47
+ },
48
+ "sideEffects": false,
49
+ "files": [
50
+ "dist",
51
+ "index.d.ts"
29
52
  ],
30
- "license": "MIT",
53
+ "scripts": {
54
+ "bench": "tsx bench.ts",
55
+ "build": "tsup --config ../../tsup.config.ts",
56
+ "docs": "tsx ../../scripts/generate-readmes.ts",
57
+ "test": "npm-run-all --npm-path npm test:*",
58
+ "test:tape": "tsx test.ts",
59
+ "test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
60
+ },
31
61
  "devDependencies": {
32
- "@turf/bbox-polygon": "*",
33
- "@turf/random": "*",
34
- "@types/node": "*",
35
- "benchmark": "*",
36
- "documentation": "*",
37
- "load-json-file": "*",
38
- "tap": "*",
39
- "tape": "*",
40
- "typescript": "*",
41
- "write-json-file": "*"
62
+ "@turf/bbox-polygon": "^7.0.0-alpha.0+135b898",
63
+ "@turf/random": "^7.0.0-alpha.0+135b898",
64
+ "benchmark": "^2.1.4",
65
+ "load-json-file": "^7.0.1",
66
+ "npm-run-all": "^4.1.5",
67
+ "tape": "^5.7.2",
68
+ "tsup": "^8.0.1",
69
+ "tsx": "^4.6.2",
70
+ "typescript": "^5.2.2",
71
+ "write-json-file": "^5.0.0"
42
72
  },
43
73
  "dependencies": {
44
- "@turf/bbox": "*",
45
- "@turf/helpers": "6.x",
46
- "@turf/meta": "6.x",
74
+ "@turf/bbox": "^7.0.0-alpha.0+135b898",
75
+ "@turf/helpers": "^7.0.0-alpha.0+135b898",
76
+ "@turf/meta": "^7.0.0-alpha.0+135b898",
47
77
  "@types/geojson": "7946.0.8",
48
78
  "rbush": "^3.0.1"
49
- }
79
+ },
80
+ "gitHead": "135b89890bc7beea22d39fbeb9100ef2a8c85fea"
50
81
  }
package/CHANGELOG.md DELETED
@@ -1,47 +0,0 @@
1
-
2
- # Changelog
3
-
4
- ## 3.1.0 - 2018-02-05
5
-
6
- - Improve coverage testing to 100%
7
- - Support Array of Features to `.load()` method
8
- - Allow strict Typing when defining Tree (ex: `const tree = rbush<Polygon>()`)
9
- - Update documentation
10
- - Add `equals` param to `.remove()` method
11
- - Drop BBox from search/remove methods
12
- - Add support for 6 position BBox
13
-
14
- ## 3.0.0 - 2018-02-04
15
-
16
- - Update Typescript definition
17
- - Drop ES Modules in favor of Typescript
18
-
19
- ## 2.2.0 - 2017-11-22
20
-
21
- - Clean up Rollup build
22
-
23
- ## 2.1.0 - 2017-10-16
24
-
25
- - Added Rollup to build CommonJS (`main.js`)
26
-
27
- ## 2.0.4 - 2017-10-10
28
-
29
- - ~Drop Rollup~
30
- - Update Typescript definition
31
-
32
- ## 2.0.0 - 2017-10-01
33
-
34
- - Support ES modules
35
-
36
- ## 1.1.1 - 2017-07-15
37
-
38
- - Replaced `const` with `var` for pure ES5 compatibility
39
-
40
- ## 1.1.0 - 2017-06-01
41
-
42
- - Add `bbox` support as valid input
43
- - Drop rollup build (ES5 npm package is plenty)
44
-
45
- ## 1.0.0 - 2017-03-20
46
-
47
- - Initialize GeoJSON RBush from https://github.com/Turfjs/turf/pull/609
package/index.js DELETED
@@ -1,208 +0,0 @@
1
- var rbush = require('rbush/rbush');
2
- var helpers = require('@turf/helpers');
3
- var meta = require('@turf/meta');
4
- var turfBBox = require('@turf/bbox').default;
5
- var featureEach = meta.featureEach;
6
- var coordEach = meta.coordEach;
7
- var polygon = helpers.polygon;
8
- var featureCollection = helpers.featureCollection;
9
-
10
- /**
11
- * GeoJSON implementation of [RBush](https://github.com/mourner/rbush#rbush) spatial index.
12
- *
13
- * @name rbush
14
- * @param {number} [maxEntries=9] defines the maximum number of entries in a tree node. 9 (used by default) is a
15
- * reasonable choice for most applications. Higher value means faster insertion and slower search, and vice versa.
16
- * @returns {RBush} GeoJSON RBush
17
- * @example
18
- * var geojsonRbush = require('geojson-rbush').default;
19
- * var tree = geojsonRbush();
20
- */
21
- function geojsonRbush(maxEntries) {
22
- var tree = new rbush(maxEntries);
23
- /**
24
- * [insert](https://github.com/mourner/rbush#data-format)
25
- *
26
- * @param {Feature} feature insert single GeoJSON Feature
27
- * @returns {RBush} GeoJSON RBush
28
- * @example
29
- * var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);
30
- * tree.insert(poly)
31
- */
32
- tree.insert = function (feature) {
33
- if (feature.type !== 'Feature') throw new Error('invalid feature');
34
- feature.bbox = feature.bbox ? feature.bbox : turfBBox(feature);
35
- return rbush.prototype.insert.call(this, feature);
36
- };
37
-
38
- /**
39
- * [load](https://github.com/mourner/rbush#bulk-inserting-data)
40
- *
41
- * @param {FeatureCollection|Array<Feature>} features load entire GeoJSON FeatureCollection
42
- * @returns {RBush} GeoJSON RBush
43
- * @example
44
- * var polys = turf.polygons([
45
- * [[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]],
46
- * [[[-93, 32], [-83, 32], [-83, 39], [-93, 39], [-93, 32]]]
47
- * ]);
48
- * tree.load(polys);
49
- */
50
- tree.load = function (features) {
51
- var load = [];
52
- // Load an Array of Features
53
- if (Array.isArray(features)) {
54
- features.forEach(function (feature) {
55
- if (feature.type !== 'Feature') throw new Error('invalid features');
56
- feature.bbox = feature.bbox ? feature.bbox : turfBBox(feature);
57
- load.push(feature);
58
- });
59
- } else {
60
- // Load a FeatureCollection
61
- featureEach(features, function (feature) {
62
- if (feature.type !== 'Feature') throw new Error('invalid features');
63
- feature.bbox = feature.bbox ? feature.bbox : turfBBox(feature);
64
- load.push(feature);
65
- });
66
- }
67
- return rbush.prototype.load.call(this, load);
68
- };
69
-
70
- /**
71
- * [remove](https://github.com/mourner/rbush#removing-data)
72
- *
73
- * @param {Feature} feature remove single GeoJSON Feature
74
- * @param {Function} equals Pass a custom equals function to compare by value for removal.
75
- * @returns {RBush} GeoJSON RBush
76
- * @example
77
- * var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);
78
- *
79
- * tree.remove(poly);
80
- */
81
- tree.remove = function (feature, equals) {
82
- if (feature.type !== 'Feature') throw new Error('invalid feature');
83
- feature.bbox = feature.bbox ? feature.bbox : turfBBox(feature);
84
- return rbush.prototype.remove.call(this, feature, equals);
85
- };
86
-
87
- /**
88
- * [clear](https://github.com/mourner/rbush#removing-data)
89
- *
90
- * @returns {RBush} GeoJSON Rbush
91
- * @example
92
- * tree.clear()
93
- */
94
- tree.clear = function () {
95
- return rbush.prototype.clear.call(this);
96
- };
97
-
98
- /**
99
- * [search](https://github.com/mourner/rbush#search)
100
- *
101
- * @param {BBox|FeatureCollection|Feature} geojson search with GeoJSON
102
- * @returns {FeatureCollection} all features that intersects with the given GeoJSON.
103
- * @example
104
- * var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);
105
- *
106
- * tree.search(poly);
107
- */
108
- tree.search = function (geojson) {
109
- var features = rbush.prototype.search.call(this, this.toBBox(geojson));
110
- return featureCollection(features);
111
- };
112
-
113
- /**
114
- * [collides](https://github.com/mourner/rbush#collisions)
115
- *
116
- * @param {BBox|FeatureCollection|Feature} geojson collides with GeoJSON
117
- * @returns {boolean} true if there are any items intersecting the given GeoJSON, otherwise false.
118
- * @example
119
- * var poly = turf.polygon([[[-78, 41], [-67, 41], [-67, 48], [-78, 48], [-78, 41]]]);
120
- *
121
- * tree.collides(poly);
122
- */
123
- tree.collides = function (geojson) {
124
- return rbush.prototype.collides.call(this, this.toBBox(geojson));
125
- };
126
-
127
- /**
128
- * [all](https://github.com/mourner/rbush#search)
129
- *
130
- * @returns {FeatureCollection} all the features in RBush
131
- * @example
132
- * tree.all()
133
- */
134
- tree.all = function () {
135
- var features = rbush.prototype.all.call(this);
136
- return featureCollection(features);
137
- };
138
-
139
- /**
140
- * [toJSON](https://github.com/mourner/rbush#export-and-import)
141
- *
142
- * @returns {any} export data as JSON object
143
- * @example
144
- * var exported = tree.toJSON()
145
- */
146
- tree.toJSON = function () {
147
- return rbush.prototype.toJSON.call(this);
148
- };
149
-
150
- /**
151
- * [fromJSON](https://github.com/mourner/rbush#export-and-import)
152
- *
153
- * @param {any} json import previously exported data
154
- * @returns {RBush} GeoJSON RBush
155
- * @example
156
- * var exported = {
157
- * "children": [
158
- * {
159
- * "type": "Feature",
160
- * "geometry": {
161
- * "type": "Point",
162
- * "coordinates": [110, 50]
163
- * },
164
- * "properties": {},
165
- * "bbox": [110, 50, 110, 50]
166
- * }
167
- * ],
168
- * "height": 1,
169
- * "leaf": true,
170
- * "minX": 110,
171
- * "minY": 50,
172
- * "maxX": 110,
173
- * "maxY": 50
174
- * }
175
- * tree.fromJSON(exported)
176
- */
177
- tree.fromJSON = function (json) {
178
- return rbush.prototype.fromJSON.call(this, json);
179
- };
180
-
181
- /**
182
- * Converts GeoJSON to {minX, minY, maxX, maxY} schema
183
- *
184
- * @private
185
- * @param {BBox|FeatureCollection|Feature} geojson feature(s) to retrieve BBox from
186
- * @returns {Object} converted to {minX, minY, maxX, maxY}
187
- */
188
- tree.toBBox = function (geojson) {
189
- var bbox;
190
- if (geojson.bbox) bbox = geojson.bbox;
191
- else if (Array.isArray(geojson) && geojson.length === 4) bbox = geojson;
192
- else if (Array.isArray(geojson) && geojson.length === 6) bbox = [geojson[0], geojson[1], geojson[3], geojson[4]];
193
- else if (geojson.type === 'Feature') bbox = turfBBox(geojson);
194
- else if (geojson.type === 'FeatureCollection') bbox = turfBBox(geojson);
195
- else throw new Error('invalid geojson')
196
-
197
- return {
198
- minX: bbox[0],
199
- minY: bbox[1],
200
- maxX: bbox[2],
201
- maxY: bbox[3]
202
- };
203
- };
204
- return tree;
205
- }
206
-
207
- module.exports = geojsonRbush;
208
- module.exports.default = geojsonRbush;