gis-tools-ts
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
83 lines • 2.32 kB
TypeScript
import type { S2CellId } from '../../index.js';
/** The kind of input required to store a vector for proper indexing */
export interface VectorKey {
cell: S2CellId;
}
/** Represents a vector store or an array */
export interface VectorStore<V> {
push: (value: V) => void;
get: (index: number | S2CellId) => Promise<V>;
has: (key: number | S2CellId) => boolean | Promise<boolean>;
length: number;
values: () => AsyncGenerator<V>;
sort: (() => void) | (() => Promise<void>);
[Symbol.asyncIterator]: () => AsyncGenerator<V>;
close: () => void;
}
/** A constructor for a vector store */
export type VectorStoreConstructor<V extends VectorKey> = new () => VectorStore<V>;
/**
* # Vector Store
*
* ## Description
* A local vector store
*
* ## Usage
* ```ts
* import { Vector } from 'gis-tools-ts';
* import type { VectorKey } from 'gis-tools-ts';
*
* interface Data extends VectorKey { name: string };
*
* const vec = new Vector<Data>();
* // push an entry
* vec.push({ cell: 1n, name: 'test' });
* vec.push({ cell: 1n, name: 'test2' });
* // check if a key exists
* vec.has(1n); // true
* // get length of the store
* console.log(vec.length); // 2
*
* // iterate over the store
* for await (const entry of vec) console.log(entry);
*
* // close the store
* vec.close();
* ```
*/
export declare class Vector<V extends VectorKey> implements VectorStore<V> {
#private;
/**
* Push a value into the store
* @param value - the value to store
*/
push(value: V): void;
/**
* @param index - the position in the store to get the value from
* @returns the value
*/
get(index: number | S2CellId): Promise<V>;
/**
* Check if the key exists
* @param key - the key
* @returns true if the key exists
*/
has(key: number | S2CellId): boolean;
/** @returns the length of the store */
get length(): number;
/**
* iterate through the values
* @yields {V} - the values iterator
*/
values(): AsyncGenerator<V>;
/** Sort the store in place */
sort(): void;
/**
* iterate through the values
* @returns an iterator
*/
[Symbol.asyncIterator](): AsyncGenerator<V>;
/** Closes the store */
close(): void;
}
//# sourceMappingURL=index.d.ts.map