Skip to main content

Class: GeoKdTree<T>

Defined in: src/sdk/utils/datastructures/GeoKdTree.ts:29

A spatial tree which is keyed on points on Earth's surface and allows searching for elements based on the great- circle distances from their keys to a query point.

Type Parameters​

Type Parameter
T

Constructors​

Constructor​

new GeoKdTree<T>(keyFunc): GeoKdTree<T>

Defined in: src/sdk/utils/datastructures/GeoKdTree.ts:46

Constructor.

Parameters​

ParameterTypeDescription
keyFunc(element, out) => Float64ArrayA function which generates keys from elements. Keys are cartesian representations of points on Earth's surface.

Returns​

GeoKdTree<T>

Throws​

Error if the dimension count is less than 2.

Methods​

clear()​

clear(): void

Defined in: src/sdk/utils/datastructures/GeoKdTree.ts:235

Removes all elements from this tree.

Returns​

void


insert()​

insert(element): void

Defined in: src/sdk/utils/datastructures/GeoKdTree.ts:183

Inserts an element into this tree. This operation will trigger a rebalancing if, after the insertion, the length of this tree's longest branch is more than twice the length of the shortest branch.

Parameters​

ParameterTypeDescription
elementTThe element to insert.

Returns​

void


insertAll()​

insertAll(elements): void

Defined in: src/sdk/utils/datastructures/GeoKdTree.ts:191

Inserts a batch of elements into this tree. This tree will be rebalanced after the elements are inserted.

Parameters​

ParameterTypeDescription
elementsIterable<T>An iterable of the elements to insert.

Returns​

void


rebuild()​

rebuild(): void

Defined in: src/sdk/utils/datastructures/GeoKdTree.ts:228

Rebuilds and balances this tree.

Returns​

void


remove()​

remove(element): boolean

Defined in: src/sdk/utils/datastructures/GeoKdTree.ts:200

Removes an element from this tree. This tree will be rebalanced after the element is removed.

Parameters​

ParameterTypeDescription
elementTThe element to remove.

Returns​

boolean

Whether the element was removed.


removeAll()​

removeAll(elements): boolean

Defined in: src/sdk/utils/datastructures/GeoKdTree.ts:209

Removes a batch of elements from this tree. This tree will be rebalanced after the elements are removed.

Parameters​

ParameterTypeDescription
elementsIterable<T>An iterable of the elements to remove.

Returns​

boolean

Whether at least one element was removed.


removeAndInsert()​

removeAndInsert(toRemove, toInsert): void

Defined in: src/sdk/utils/datastructures/GeoKdTree.ts:221

Removes elements from this tree, then inserts elements into this tree as a single operation. The tree will be rebalanced at the end of the operation.

Using this method is more efficient than calling removeAll() and insertAll() separately.

Parameters​

ParameterTypeDescription
toRemoveIterable<T>An iterable of the elements to remove.
toInsertIterable<T>An iterable of the elements to insert.

Returns​

void


Call Signature​

search(lat, lon, radius, visitor): void

Defined in: src/sdk/utils/datastructures/GeoKdTree.ts:58

Searches this tree for elements located near a query point and visits each of them with a function.

Parameters​
ParameterTypeDescription
latnumberThe latitude of the query point, in degrees.
lonnumberThe longitude of the query point, in degrees.
radiusnumberThe radius around the query point to search, in great-arc radians.
visitorGeoKdTreeSearchVisitor<T>A visitor function. This function will be called once per element found within the search radius. If the visitor returns true, then the search will continue; if the visitor returns false, the search will immediately halt.
Returns​

void

Call Signature​

search(center, radius, visitor): void

Defined in: src/sdk/utils/datastructures/GeoKdTree.ts:67

Searches this tree for elements located near a query point and visits each of them with a function.

Parameters​
ParameterTypeDescription
centerReadonly<Omit<Float64Array<ArrayBufferLike>, "set" | "sort" | "copyWithin">> | LatLonInterfaceThe query point.
radiusnumberThe radius around the query point to search, in great-arc radians.
visitorGeoKdTreeSearchVisitor<T>A visitor function. This function will be called once per element found within the search radius. If the visitor returns true, then the search will continue; if the visitor returns false, the search will immediately halt.
Returns​

void

Call Signature​

search(lat, lon, radius, maxResultCount, out, filter?): T[]

Defined in: src/sdk/utils/datastructures/GeoKdTree.ts:79

Searches this tree for elements located near a query point and returns them in order of increasing distance from the query key.

Parameters​
ParameterTypeDescription
latnumberThe latitude of the query point, in degrees.
lonnumberThe longitude of the query point, in degrees.
radiusnumberThe radius around the query point to search, in great-arc radians.
maxResultCountnumberThe maximum number of search results to return.
outT[]An array in which to store the search results.
filter?GeoKdTreeSearchFilter<T>A function to filter the search results.
Returns​

T[]

An array containing the search results, in order of increasing distance from the query key.

Call Signature​

search(center, radius, maxResultCount, out, filter?): T[]

Defined in: src/sdk/utils/datastructures/GeoKdTree.ts:90

Searches this tree for elements located near a query point and returns them in order of increasing distance from the query key.

Parameters​
ParameterTypeDescription
centerReadonly<Omit<Float64Array<ArrayBufferLike>, "set" | "sort" | "copyWithin">> | LatLonInterfaceThe query point.
radiusnumberThe radius around the query point to search, in great-arc radians.
maxResultCountnumberThe maximum number of search results to return.
outT[]An array in which to store the search results.
filter?GeoKdTreeSearchFilter<T>A function to filter the search results.
Returns​

T[]

An array containing the search results, in order of increasing distance from the query key.