s2-tools
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
54 lines • 1.36 kB
JavaScript
import { S2FileStore } from '../file';
/** File based vector store */
export class FileVector {
#store;
/** @param fileName - the path + file name without the extension */
constructor(fileName) {
this.#store = new S2FileStore(fileName);
}
/** @returns the length of the store */
get length() {
return this.#store.length;
}
/**
* Push a value into the store
* @param value - the value to store
*/
push(value) {
this.#store.set(value.cell, value);
}
/**
* @param index - the position in the store to get the value from
* @returns the value
*/
async get(index) {
const value = await this.#store.get(index);
if (value === undefined)
throw new Error('Value not found');
return value[0];
}
/** Sort the store */
async sort() {
await this.#store.sort();
}
/**
* iterate through the values
* @yields an iterator
*/
async *values() {
for await (const { value } of this.#store.entries())
yield value;
}
/**
* iterate through the values
* @returns an iterator
*/
[Symbol.asyncIterator]() {
return this.values();
}
/** Closes the store */
close() {
this.#store.close(true);
}
}
//# sourceMappingURL=file.js.map