new GeojsonFlatbush(numItems, nodeSizeopt, ArrayTypeopt) → {GeojsonFlatbush}
Instantiates a GeojsonFlatbush index.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
numItems |
Number | Number of items to store in static index. | ||
nodeSize |
Number |
<optional> |
16 | Size of the tree node. |
ArrayType |
Number |
<optional> |
Float64Array | Array type coordinate storage. |
Returns:
New instance of GeojsonFlatbush.
- Type
- GeojsonFlatbush
Example
// Initialize GeojsonFlatbush for 1000 items.
const index = new GeojsonFlatbush(1000)
Members
index :Flatbush
Flatbush spatial index.
Type:
- Flatbush
Methods
(static) from(data) → {GeojsonFlatbush}
Instantiates a GeojsonFlatbush index from raw 'data' member.
Parameters:
Name | Type | Description |
---|---|---|
data |
ArrayBuffer | Raw indexing data array. |
Returns:
New instance of GeojsonFlatbush.
- Type
- GeojsonFlatbush
Example
// Reconstruct the index from a raw array buffer.
const index = GeojsonFlatbush.from(e.index.data);
add(data)
Adds a single GeoJSON to the index.
Parameters:
Name | Type | Description |
---|---|---|
data |
GeoJSON | Array | GeoJSON or bounding box array. |
Example
// Fill the index with a line string.
const line = turf.lineString([[0, 0], [1, 1]]);
index.add(line);
finish()
Performs indexing of the added GeoJSON.
Example
// Perform the indexing. Should only be called once when done adding data.
index.finish()
load(data)
Bulk load a collection to the index.
Parameters:
Name | Type | Description |
---|---|---|
data |
FeatureCollection | Array | GeoJSON or array of features/bboxes. |
Example
// Fill the index with a feature collection.
const collection = turf.featureCollection([
turf.lineString([[0, 0], [1, 1]]),
turf.lineString([[0, 1], [1, 2]]),
]);
index.load(collection);
neighbors(point, maxResultsopt, maxDistanceopt, collectionopt, filterFnopt) → {FeatureCollection|Array}
Finds the K nearest neighbors from a point.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
point |
point | Query point. | ||
maxResults |
Number |
<optional> |
Infinity | Maximum number of results (= K). |
maxDistance |
Number |
<optional> |
Infinity | Maximum distance from point allowed. |
collection |
GeoJSON |
<optional> |
null | Source collection to select items from. |
filterFn |
function |
<optional> |
Called on every found item (passing an item index) and only includes it if function returned a truthy value. |
Returns:
Features found or their IDs.
- Type
- FeatureCollection | Array
Example
// Find the 5 nearest neighbors.
const point = turf.point([0,0]);
const neighbors = index.neighbors(point, 5, Infinity, collection);
search(geojson, collectionopt, filterFnopt) → {Array|FeatureCollection}
Find items in the bounding box of the GeoJSON.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
geojson |
GeoJSON | Array | GeoJSON or its bounding box. | |
collection |
GeoJSON |
<optional> |
Source collection from which to return items. |
filterFn |
function |
<optional> |
Called on every found item (passing an item index) and only includes it if the function returned a truthy value. |
Returns:
IDs or features found.
- Type
- Array | FeatureCollection
Example
// Make a GeoJSON query.
const polygon = turf.polygon([[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]]);
const found = index.search(polygon, collection);