interpolators.md
February 10, 2026 ยท View on GitHub
Data Interpolation
Description
Interpolation is the process of filling in missing data in a dataset. This can be done in many different ways. Four common methods for GIS are average, nearest, inverse distance weighted, and lanczos.
Lanczos is the default method and arguably the most useful for interpolating RGBA spatial data.
The bilinear interpolation exists, but is not recommended as it can fail.
Usage
Acess any of the interpolators
import { getInterpolation, getRGBAInterpolation } from 'geo-tools-ts';
// get average interpolation
const average = getInterpolation('average');
// get nearest interpolation
const nearest = getInterpolation('nearest');
// get idw interpolation
const idw = getInterpolation('idw');
// get lanczos interpolation
const lanczos = getInterpolation('lanczos');
// get average interpolation
// RGBA
// get average interpolation
const rgbaAverage = getRGBAInterpolation('average');
// get nearest interpolation
const rgbaNearest = getRGBAInterpolation('nearest');
// get idw interpolation
const rgbaIDW = getRGBAInterpolation('idw');
// get lanczos interpolation
const rgbaLanczos = getRGBAInterpolation('lanczos');
Average Neighbor Interpolation
Finds the avarage point in the reference data to the given point and returns its value.
import { averageInterpolation, 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: number = averageInterpolation<TempData>(point, data, (p) => p.m.temp);
If you want to process RGB(A) data, useHelper function.
import { rgbaAverageInterpolation } from 'gis-tools-ts';
import type { RGBA } from 'gis-tools-ts';
const interpolatedRGBAValue: RGBA = rgbaAverageInterpolation(point, data);
Nearest Neighbor Interpolation
Finds the nearest point in the reference data to the given point and returns its value.
import { nearestInterpolation, 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 = nearestInterpolation<TempData>(point, data, (p) => p.m.temp);
If you want to process RGB(A) data, useHelper function.
import { rgbaNearestInterpolation } from 'gis-tools-ts';
import type { RGBA } from 'gis-tools-ts';
const interpolatedRGBAValue: RGBA = rgbaNearestInterpolation(point, data);
Inverse Distance Weighting Interpolation
Given a reference of data, interpolate a point using inverse distance weighting
import { idwInterpolation, 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 = idwInterpolation<TempData>(point, data, (p) => p.m.temp);
If you want to process RGB(A) data, useHelper function.
import { rgbaIDWInterpolation } from 'gis-tools-ts';
import type { RGBA } from 'gis-tools-ts';
const interpolatedRGBAValue: RGBA = rgbaIDWInterpolation(point, data);
Lanczos Interpolation
Perform interpolation using the Lanczos filter. This method uses a kernel-based approach to weigh contributions from nearby points, providing a balance between smoothing and sharpness.
import { lanczosInterpolation, 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 = lanczosInterpolation<TempData>(point, data, (p) => p.m.temp);
If you want to process RGB(A) data, useHelper function.
import { rgbaLanczosInterpolation } from 'gis-tools-ts';
import type { RGBA } from 'gis-tools-ts';
const interpolatedRGBAValue: RGBA = rgbaLanczosInterpolation(point, data);