s2-tools
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
102 lines • 3.66 kB
TypeScript
import type { S1ChordAngle } from '../geometry/s1/chordAngle';
import type { Stringifiable } from '../dataStore';
import type { Face, Point3D } from '../geometry';
import type { Uint64, Uint64Cell } from '../dataStructures/uint64';
import type { VectorStore, VectorStoreConstructor } from '../dataStore';
/** The kind of input required to store a point for proper indexing */
export interface PointShape<T = Stringifiable> {
cell: Uint64Cell;
point: Point3D;
data: T;
}
/**
* # Point Index
*
* ## Description
* An index of cells with radius queries
* Assumes the data is {@link Stringifiable}
*
* ## Usage
* ```ts
* import { PointIndex } from 's2-tools';
* import { FileVector } from 's2-tools/file';
*
* const pointIndex = new PointIndex();
* // or used a file based store
* const pointIndex = new PointIndex(FileVector);
*
* // insert a lon-lat
* pointIndex.insertLonLat(lon, lat, data);
* // insert an STPoint
* pointIndex.insertFaceST(face, s, t, data);
*
* // after adding data build the index. NOTE: You don't have to call this, it will be called
* // automatically when making a query
* await pointIndex.sort();
*
* // you can search a range
* const points = await pointIndex.searchRange(low, high);
* // or a radius
* const points = await pointIndex.searchRadius(center, radius);
* ```
*/
export declare class PointIndex<T extends Stringifiable = Stringifiable> {
#private;
/** @param store - the store to index. May be an in memory or disk */
constructor(store?: VectorStoreConstructor<PointShape<T>>);
/**
* Set the index store to a defined one. Useful for file based stores where we want to reuse data
* @param store - the index store
*/
setStore(store: VectorStore<PointShape<T>>): void;
/**
* Insert a point3D and its corresponding data to the index
* @param point - the point to be indexed
* @param data - the data associated with the point
*/
insert(point: Point3D, data: T): void;
/**
* Add a lon-lat pair to the cluster
* @param lon - longitude in degrees
* @param lat - latitude in degrees
* @param data - the data associated with the point
*/
insertLonLat(lon: number, lat: number, data: T): void;
/**
* Insert an STPoint to the index
* @param face - the face of the cell
* @param s - the s coordinate
* @param t - the t coordinate
* @param data - the data associated with the point
*/
insertFaceST(face: Face, s: number, t: number, data: T): void;
/**
* iterate through the points
* @yields a PointShape<T>
*/
[Symbol.asyncIterator](): AsyncGenerator<PointShape<T>>;
/** Sort the index in place if unsorted */
sort(): Promise<void>;
/**
* Find the starting index of a search
* @param id - input id to seek the starting index of the search
* @returns the starting index
*/
lowerBound(id: Uint64): Promise<number>;
/**
* Search for points given a range of low and high ids
* @param low - the lower bound
* @param high - the upper bound
* @param maxResults - the maximum number of results to return
* @returns the points in the range
*/
searchRange(low: Uint64, high: Uint64, maxResults?: number): Promise<PointShape<T>[]>;
/**
* @param target - the point to search
* @param radius - the search radius
* @param maxResults - the maximum number of results
* @returns the points within the radius
*/
searchRadius(target: Point3D, radius: S1ChordAngle, maxResults?: number): Promise<PointShape<T>[]>;
}
//# sourceMappingURL=pointIndex.d.ts.map