UNPKG

s2-tools

Version:

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

175 lines 6.9 kB
import type { Face, FeatureIterator, Properties, RGBA, S2Feature, S2PMTilesReader, VectorFeature } from '../..'; import type { Metadata } from 's2-tilejson'; /** Elevation point used by elevation readers */ export interface ElevationPoint extends Properties { elev: number; } /** Tile's metadata */ export interface TileMetadata { zoom: number; x: number; y: number; } /** S2 Tile's metadata */ export interface S2TileMetadata { face: Face; zoom: number; x: number; y: number; } /** Elevation converter */ export type ElevationConverter = (r: number, g: number, b: number, a?: number) => number; /** * @param r - red * @param g - green * @param b - blue * @returns - elevation */ export declare function convertTerrariumElevationData(r: number, g: number, b: number): number; /** * @param r - red * @param g - green * @param b - blue * @returns - elevation */ export declare function convertMapboxElevationData(r: number, g: number, b: number): number; /** * # Raster Tiles Reader * * ## Description * Read an entire archive of raster tiles, where the max zoom data is iterated upon * * Supports reading either RGB(A) data and/or RGB(A) encoded elevation data. * * NOTE: Consider using the RasterTilesFileReader from `s2-tools/file` instead for local access. * * ## Usage * ```ts * import { RasterTilesReader, convertTerrariumElevationData } from 's2-tools'; * * // creates a reader for a tile set treating the max zoom as 3 instead of the metadata's max zoom * const reader = new RasterTilesReader('https://example.com/satellite-data', 3); * // example of reading in an elevation dataset * const reader2 = new RasterTilesReader('https://example.com/terrariumData', -1, convertTerrariumElevationData); * * // grab the metadata * const metadata = await reader.getMetadata(); * * // grab a WM tile * const tile1 = await reader.getTile(0, 0, 0); * // or if it's an S2 tile spec * const tile2 = await reader.getTileS2(0, 0, 0, 0); * * // grab all the max zoom tiles: * for await (const tile of reader) { * console.log(tile); * } * ``` */ export declare class RasterTilesReader<T extends Properties = RGBA | ElevationPoint> implements FeatureIterator<S2TileMetadata | TileMetadata, T, Properties> { readonly input: string | S2PMTilesReader; readonly threshold: number; readonly converter?: ElevationConverter | undefined; metadata?: Metadata; /** * @param input - the URL path or S2PMTilesReader to read from * @param threshold - if non-zero its the max zoom to read all tiles in the FeatureIterator * @param converter - the elevation converter */ constructor(input: string | S2PMTilesReader, threshold?: number, converter?: ElevationConverter | undefined); /** * Get the metadata of the archive * @returns - the metadata */ getMetadata(): Promise<Metadata>; /** * Grab the tile at the given zoom-x-y coordinates * @param zoom - the zoom level of the tile * @param x - the x coordinate of the tile * @param y - the y coordinate of the tile * @returns - the tile */ getTile(zoom: number, x: number, y: number): Promise<RasterTileReader<T> | undefined>; /** * Grab the tile at the given (face, zoom, x, y) coordinates * @param face - the Open S2 projection face * @param zoom - the zoom level of the tile * @param x - the x coordinate of the tile * @param y - the y coordinate of the tile * @returns - the tile */ getTileS2(face: Face, zoom: number, x: number, y: number): Promise<RasterS2TileReader<T> | undefined>; /** * Return true if the tile exists * @param zoom - the zoom level of the tile * @param x - the x coordinate of the tile * @param y - the y coordinate of the tile * @returns - true if the tile exists */ hasTile(zoom: number, x: number, y: number): Promise<boolean>; /** * Return true if the tile exists * @param face - the Open S2 projection face * @param zoom - the zoom level of the tile * @param x - the x coordinate of the tile * @param y - the y coordinate of the tile * @returns - true if the tile exists */ hasTileS2(face: Face, zoom: number, x: number, y: number): Promise<boolean>; /** * Iterate over all tiles in the archive * @yields - the each of the tile's pixel RGBA data as lon-lat or S2 s-t coordinates with the RGBA as m-values */ [Symbol.asyncIterator](): AsyncGenerator<S2Feature<S2TileMetadata, T, Properties> | VectorFeature<TileMetadata, T, Properties>>; } /** * Raster Tile Reader */ export declare class RasterTileReader<T extends Properties = RGBA | ElevationPoint> implements FeatureIterator<TileMetadata, T, Properties> { readonly zoom: number; readonly x: number; readonly y: number; readonly image: ImageData; readonly tmsStyle: boolean; readonly converter?: ElevationConverter | undefined; /** * @param zoom - the zoom level of the tile * @param x - the x coordinate of the tile * @param y - the y coordinate of the tile * @param image - the raw RGB(A) image data * @param tmsStyle - if true, the y is inverted * @param converter - the elevation converter (if provided its not an RGBA image but rather elevation data) */ constructor(zoom: number, x: number, y: number, image: ImageData, tmsStyle?: boolean, converter?: ElevationConverter | undefined); /** * Iterate over all tiles in the archive * @yields - the each of the tile's pixel RGBA data as lon-lat coordinates with the RGBA as m-values */ [Symbol.asyncIterator](): AsyncGenerator<VectorFeature<TileMetadata, T, Properties>>; } /** * S2 Raster Tile Reader */ export declare class RasterS2TileReader<T extends Properties = RGBA | ElevationPoint> implements FeatureIterator<S2TileMetadata, T, Properties> { readonly face: Face; readonly zoom: number; readonly x: number; readonly y: number; readonly image: ImageData; readonly converter?: ElevationConverter | undefined; /** * @param face - the Open S2 projection face * @param zoom - the zoom level of the tile * @param x - the x coordinate of the tile * @param y - the y coordinate of the tile * @param image - the raw image RGB(A) data * @param converter - the elevation converter (if provided its not an RGBA image but rather elevation data) */ constructor(face: Face, zoom: number, x: number, y: number, image: ImageData, converter?: ElevationConverter | undefined); /** * Iterate over all tiles in the archive * @yields - the each of the tile's pixel RGBA data as S2 s-t coordinates with the RGBA as m-values */ [Symbol.asyncIterator](): AsyncGenerator<S2Feature<S2TileMetadata, T, Properties>>; } //# sourceMappingURL=index.d.ts.map