UNPKG

gis-tools-ts

Version:

A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.

126 lines 4.12 kB
export * from './json/index.js'; export * from './pmtiles/index.js'; export * from './s2tiles/index.js'; export * from './tiles/index.js'; /** A Tile writer designed for testing. */ export class BufferTileWriter { metadata = null; tiles = new Map(); /** * Write a tile to the folder location given its (z, x, y) coordinates. * @param zoom - the zoom level * @param x - the tile X coordinate * @param y - the tile Y coordinate * @param data - the tile data to store */ async writeTileWM(zoom, x, y, data) { const key = `${zoom}/${x}/${y}`; await this.tiles.set(key, data); } /** * Write a tile to the folder location given its (face, zoom, x, y) coordinates. * @param face - the Open S2 projection face * @param zoom - the zoom level * @param x - the tile X coordinate * @param y - the tile Y coordinate * @param data - the tile data to store */ async writeTileS2(face, zoom, x, y, data) { const key = `${face}/${zoom}/${x}/${y}`; await this.tiles.set(key, data); } /** * Write a time series tile to the folder location given its (t, z, x, y) coordinates. * @param time - the date of the data * @param zoom - the zoom level * @param x - the tile X coordinate * @param y - the tile Y coordinate * @param data - the tile data to store */ async writeTemporalTileWM(time, zoom, x, y, data) { const key = `${time.getTime()}/${zoom}/${x}/${y}`; await this.tiles.set(key, data); } /** * Write a time series tile to the folder location given its (face, zoom, x, y) coordinates. * @param time - the date of the data * @param face - the Open S2 projection face * @param zoom - the zoom level * @param x - the tile X coordinate * @param y - the tile Y coordinate * @param data - the tile data to store */ async writeTemporalTileS2(time, face, zoom, x, y, data) { const key = `${time.getTime()}/${face}/${zoom}/${x}/${y}`; await this.tiles.set(key, data); } /** * Finish writing by building the header with root and leaf directories. * @param metadata - the metadata about all the tiles to store */ async commit(metadata) { this.metadata = metadata; await Promise.resolve(); } } /** Buffer writer is used on smaller datasets that are easy to write in memory. Faster then the Filesystem */ export class BufferWriter { #buffer = []; #textEncoder = new TextEncoder(); /** * Append data to the buffer * @param data - the data to append */ async append(data) { for (let i = 0; i < data.byteLength; i++) this.#buffer.push(data[i]); await true; } /** * Append string to the buffer * @param string - the string to append */ async appendString(string) { await this.append(this.#textEncoder.encode(string)); } /** * Append data to the buffer synchronously * @param data - the data to append */ appendSync(data) { for (let i = 0; i < data.byteLength; i++) this.#buffer.push(data[i]); } /** * Append string to the buffer synchronously * @param string - the string to append */ appendStringSync(string) { this.appendSync(this.#textEncoder.encode(string)); } /** * Write data to the buffer * @param data - the data to write * @param offset - where in the buffer to start */ async write(data, offset) { for (let i = 0; i < data.byteLength; i++) { this.#buffer[offset + i] = data[i]; } await true; } /** * Slice the buffer * @param start - the start of the slice * @param end - the end of the slice * @returns - the sliced buffer */ async slice(start, end) { return await new Uint8Array(this.#buffer.slice(start, end)); } /** @returns - the buffer */ commit() { return new Uint8Array(this.#buffer); } } //# sourceMappingURL=index.js.map