s2-tools
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
114 lines • 4.5 kB
TypeScript
import type { Face } from '../geometry';
import type { KDKV, KDStoreConstructor, Stringifiable } from '../dataStore';
/**
* # Point Index Fast
*
* ## Description
* An index of cells with radius queries
* Assumes the data is {@link Stringifiable}
* Because of the nature of low level language like Javascript, using u64 is slow. This index
* uses f64 which Number supports. So it is fast and efficient.
*
* ## Usage
* ```ts
* import { PointIndexFast } from 's2-tools';
* import { KDMMapSpatialIndex } from 's2-tools/mmap';
*
* const pointIndex = new PointIndexFast();
* // or used a mmap based store
* const pointIndex = new PointIndex(KDMMapSpatialIndex);
*
* // 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(minX, minY, maxX, maxY);
* // or a standard radius search
* const points = await pointIndex.searchRadius(qx, qy, r);
* // or a spherical radius search that wraps around the -180/180 boundary
* const points = await pointIndex.searchRadiusSphere(lon, lat, dist);
* ```
*/
export declare class PointIndexFast<T extends Stringifiable = Stringifiable> {
#private;
private readonly nodeSize;
/**
* @param store - the store to index. May be an in memory or disk
* @param nodeSize - the size of each kd-tree node
*/
constructor(store?: KDStoreConstructor<T>, nodeSize?: number);
/**
* Add a properly shaped point with it's x, y, and data values
* @param point - the point to be indexed
*/
insert(point: KDKV<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 PointShapeFast<T>
*/
[Symbol.iterator](): Generator<KDKV<T>>;
/** Perform indexing of the added points. */
sort(): void;
/**
* Search the index for items within a given bounding box.
* @param minX - the min x coordinate
* @param minY - the min y coordinate
* @param maxX - the max x coordinate
* @param maxY - the max y coordinate
* @param maxResults - the maximum number of results
* @returns - the items that are in range
*/
searchRange(minX: number, minY: number, maxX: number, maxY: number, maxResults?: number): Array<KDKV<T>>;
/**
* Search the index for items within a given radius.
* @param qx - the query x coordinate
* @param qy - the query y coordinate
* @param r - the radius
* @param maxResults - the maximum number of results
* @returns - the items that are in range
*/
searchRadius(qx: number, qy: number, r: number, maxResults?: number): Array<KDKV<T>>;
/**
* Search the index for items within a given radius using a spherical query.
* NOTE: Assumes the input points are lon-lat pairs in degrees.
* @param lon - longitude
* @param lat - latitude
* @param dist - max distance in meters
* @param maxResults - max number of results
* @param planetRadius - the radius of the planet (Earth by default)
* @returns - the items that are in range
*/
searchRadiusSphere(lon: number, lat: number, dist: number, maxResults?: number, planetRadius?: number): Array<KDKV<T>>;
}
/**
* Returns the distance between two points given the spherical radius in meters (defaults to earth's radius)
* @param lon1 - the first longitude
* @param lat1 - the first latitude
* @param lon2 - the second longitude
* @param lat2 - the second latitude
* @param planetRadius - the radius of the planet (Earth by default)
* @returns - the distance
*/
export declare function sphericalDistance(lon1: number, lat1: number, lon2: number, lat2: number, planetRadius?: number): number;
//# sourceMappingURL=pointIndexFast.d.ts.map