gis-tools-ts
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
147 lines • 5.93 kB
TypeScript
import { PointIndex, PointShape } from '..';
import type { Face, JSONCollection, MValue, Projection, Properties, S2CellId, VectorPoint, VectorPointM } from '../geometry';
import type { FeatureIterator, GetInterpolateValue, InterpolationFunction, InterpolationMethod, RGBA, RGBAInterpolationFunction } from '..';
import type { KVStore, KVStoreConstructor, VectorStoreConstructor } from '../dataStore';
/** Options for grid clustering */
export interface BaseGridOptions<M extends MValue = Properties | RGBA> {
/** type of point index store to use. Defaults to an in memory store */
store?: VectorStoreConstructor<PointShape<M>>;
/** projection to use */
projection?: Projection;
/** Name of the layer to build when requesting a tile */
layerName?: string;
/** min zoom to generate clusters on */
minzoom?: number;
/** max zoom level to cluster the points on */
maxzoom?: number;
/**
* Used by cell search to specify the type of interpolation to use.
* The recommendation is IDW as you want to prioritize closest data points. [default: 'idw']
*/
maxzoomInterpolation?: InterpolationMethod;
/**
* Used by cell search to specify the type of interpolation to use.
* From experimentation, lanczos is a fast algorithm that maintains the quality of the data
* [default: 'lanczos']
*/
interpolation?: InterpolationMethod;
/** Used by cell search to specify the interpolation function to use [default: 'z' value of the point] */
getInterpolationValue?: 'rgba' | GetInterpolateValue<M>;
/** Grid size, assumed pixel ratio. */
gridSize?: number;
/** Used by the cell search to specify the tile buffer size in pixels. [default: 0] */
bufferSize: number;
/** Set a null value for grid cells that are empty */
nullValue?: number | RGBA;
}
/** Options for grid clustering */
export interface GridValueOptions<M extends MValue = Properties> extends BaseGridOptions<M> {
/** Used by cell search to specify the interpolation function to use [default: 'z' value of the point] */
getInterpolationValue: GetInterpolateValue<M>;
/** Set a null value for grid cells that are empty */
nullValue?: number;
}
/** Options for raster clustering */
export interface GridRasterOptions<M extends MValue = RGBA> extends BaseGridOptions<M> {
/** Used by cell search to specify the interpolation function to use [default: 'z' value of the point] */
getInterpolationValue: 'rgba';
/** Set a null value for grid cells that are empty */
nullValue?: RGBA;
}
/** An export of the data as a grid */
export interface TileGrid extends Properties {
/** name of the layer */
name: string;
/** size of the grid including the buffer */
size: number;
/**
* flattened array of number or RGBA.
* The size of the array is gridSize * gridSize
* Access the position as `gridSize * y + x`
*/
data: number[] | RGBA[];
}
/**
* # Grid Cluster
*
* ## Description
* A cluster store to build grid data of gridSize x gridSize. The resultant tiles are filled.
* Useful for building raster tiles or other grid like data (temperature, precipitation, wind, etc).
*
* ## Usage
* ```ts
* import { PointGrid } from 'gis-tools-ts';
* const PointGrid = new PointGrid();
*
* // add a lon-lat
* PointGrid.insertLonLat(lon, lat, data);
* // add an STPoint
* PointGrid.insertFaceST(face, s, t, data);
*
* // after adding data build the clusters
* await PointGrid.buildClusters();
*
* // get the clusters for a tile
* const tile = await PointGrid.getTile(id);
* ```
*/
export declare class PointGrid<M extends MValue = Properties | RGBA> {
#private;
projection: Projection;
layerName: string;
minzoom: number;
maxzoom: number;
bufferSize: number;
maxzoomInterpolation: InterpolationFunction<M> | RGBAInterpolationFunction;
interpolation: InterpolationFunction<M> | RGBAInterpolationFunction;
getValue: GetInterpolateValue<M>;
gridSize: number;
pointIndex: PointIndex<M>;
gridTileStore: KVStore<number[] | RGBA[]>;
nullValue: number | RGBA;
isRGBA: boolean;
/**
* @param options - cluster options on how to build the cluster
* @param store - the store to use for storing all the grid tiles
*/
constructor(options?: BaseGridOptions<M> | GridRasterOptions<M>, store?: KVStoreConstructor<number[] | RGBA[]>);
/**
* Add a point to the maxzoom index. The point is a Point3D
* @param point - the point to add
*/
insert(point: VectorPointM<M>): void;
/**
* Add all points from a reader. It will try to use the M-value first, but if it doesn't exist
* it will use the feature properties data
* @param reader - a reader containing the input data
*/
insertReader(reader: FeatureIterator<unknown, M, M>): Promise<void>;
/**
* Add a vector feature. It will try to use the M-value first, but if it doesn't exist
* it will use the feature properties data
* @param data - any source of data like a feature collection or features themselves
*/
insertFeature(data: JSONCollection<unknown, M, M>): void;
/**
* Add a lon-lat pair to the cluster
* @param ll - lon-lat vector point in degrees
*/
insertLonLat(ll: VectorPoint<M>): 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: M): void;
/** Build the grid cluster tiles */
buildClusters(): Promise<void>;
/**
* Get the point data as a grid of a tile
* @param id - the cell id
* @returns - a tile grid
*/
getTile(id: S2CellId): Promise<undefined | TileGrid>;
}
//# sourceMappingURL=pointGrid.d.ts.map