UNPKG

gis-tools-ts

Version:

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

136 lines 5.7 kB
import type { GetInterpolateValue } from './index.js'; import type { MValue, Properties, RGBA, VectorPoint } from '../../index.js'; /** Kriging Model function */ export type KrigingFunction = (h: number, nugget: number, range: number, sill: number, A: number) => number; /** Kriging Models available */ export type KrigingModel = 'gaussian' | 'exponential' | 'spherical'; /** * # Kriging Distance Weighting Interpolation * * ## Description * Given a reference of data, interpolate a point using kriging distance weighting * Uses the {@link KrigingInterpolator} * * ## Usage * ```ts * import { krigingInterpolation, PointIndexFast } from 'gis-tools-ts'; * import type { VectorPoint } from 'gis-tools-ts'; * * // We have m-value data that we want to interpolate * interface TempData { temp: number; } * * const pointIndex = new PointIndexFast<TempData>(); * // add lots of points * pointIndex.insertLonLat(lon, lat, data); * // .... * * // given a point we are interested in * const point: VectorPoint = { x: 20, y: -40 }; * // get a collection of points relative to the point * const data = await pointIndex.searchRadius(point.x, point.y, radius); * * // interpolate * const interpolatedValue = krigingInterpolation<TempData>(point, data, (p) => p.m.temp); * ``` * @param point - point to interpolate * @param refData - reference data to interpolate from * @param getValue - function to get value from reference data. Can be the z value or a property in the m-values * defaults to function that returns the z value or 0 if the z value is undefined * @param model - kriging model * @param sigma2 - variance * @param alpha - diffuse * @returns - the interpolated value */ export declare function krigingInterpolation<T extends MValue = Properties>(point: VectorPoint, refData: VectorPoint<T>[], getValue?: GetInterpolateValue<T>, model?: KrigingModel, sigma2?: number, alpha?: number): number; /** * Helper function for {@link krigingInterpolation} on RGB(A) data. * Light in RGB data is logarithmically weighted, so we need to expand each component by n^2 to * get the correct weight for each component. * @param point - Point to interpolate * @param refData - Reference data points * @param model - Kriging model * @param sigma2 - Variance * @param alpha - Diffuse * @returns - The interpolated RGBA data. */ export declare function rgbaKrigingInterpolation(point: VectorPoint, refData: VectorPoint<RGBA>[], model?: KrigingModel, sigma2?: number, alpha?: number): RGBA; /** * # Kriging Interpolator * * ## Description * Interpolation using the Kriging method. Find the best fit curve for a given set of data. * You can either compute the semivariance or the variogram (expected value). * * The various variogram models can be interpreted as kernel functions for 2-dimensional coordinates * a, b and parameters nugget, range, sill and A. Reparameterized as a linear function, with * w = [nugget, (sill-nugget)/range], this becomes: * - **Gaussian**: `k(a,b) = w[0] + w[1] * ( 1 - exp{ -( ||a-b|| / range )2 / A } )` * - **Exponential**: `k(a,b) = w[0] + w[1] * ( 1 - exp{ -( ||a-b|| / range ) / A } )` * - **Spherical**: `k(a,b) = w[0] + w[1] * ( 1.5 * ( ||a-b|| / range ) - 0.5 * ( ||a-b|| / range )3 )` * * Notice the σ2 (sigma2) and α (alpha) variables, these correspond to the variance parameters of * the gaussian process and the prior of the variogram model, respectively. A diffuse α prior is * typically used; a formal mathematical definition of the model is provided below. * * The variance parameter α of the prior distribution for w should be manually set, according to: * - `w ~ N(w|0, αI)` * * Using the fitted kernel function hyperparameters and setting K as the Gram matrix, the prior and * likelihood for the gaussian process become: * - `y ~ N(y|0, K)` * - `t|y ~ N(t|y, σ2I) * * ## Usage * ```ts * import { KrigingInterpolator } from 'gis-tools-ts'; * import type { VectorPoint } from 'gis-tools-ts'; * * // We have m-value data that we want to interpolate * interface TempData { temp: number; } * * // given a point we are interested in * const point: VectorPoint = { x: 20, y: -40 }; * // get a collection of points relative to the point * const data: VectorPoint<TempData>[] = [...]; * * // interpolate * const interpolator = new KrigingInterpolator<TempData>(data, 'gaussian', (p) => p.m.temp); * const interpolatedValue = interpolator.predict(point); * ``` * * ## Links * - https://pro.arcgis.com/en/pro-app/latest/tool-reference/3d-analyst/how-kriging-works.htm */ export declare class KrigingInterpolator<T extends MValue = Properties> { private refData; t: number[]; nugget: number; range: number; sill: number; A: number; K: number[]; M: number[]; n: number; model: KrigingFunction; /** * @param refData - reference data to interpolate from * @param model - kriging model * @param getValue - function to get value from reference data. Can be the z value or a property in the m-values * @param sigma2 - variance parameter of the gaussian model * @param alpha - diffuse α prior of the variogram model */ constructor(refData: VectorPoint<T>[], model?: KrigingModel, getValue?: GetInterpolateValue<T>, sigma2?: number, alpha?: number); /** * Model prediction * @param point - point to interpolate to * @returns - predicted value */ predict(point: VectorPoint): number; /** * Variance prediction * @param point - point to interpolate to * @returns - predicted variance */ variance(point: VectorPoint): number; } //# sourceMappingURL=kriging.d.ts.map