Skip to main content

Spatial Interpolation

Spatial interpolation predicts a variable at unsampled locations from measurements with known spatial support. It cannot recover information that the sampling design never observed, and smooth maps can look more certain than the data justify.

Prerequisites​

Complete hotspots and point patterns and distance, area, and nearest neighbors. Work in a suitable projected CRS before using Euclidean distance.

Learning goals​

  • State the target variable, support, domain, metric, and boundary before interpolation.
  • Compute inverse-distance weighting (IDW) with an explicit power and zero-distance rule.
  • Validate with spatially appropriate held-out observations.
  • Separate a prediction surface from prediction uncertainty.

Assumptions before a surface​

The synthetic measurements are point-support observations in a local planar coordinate system. IDW with power p=2p=2 predicts

z^(s0)=∑id(s0,si)−2zi∑id(s0,si)−2.\widehat z(s_0)=\frac{\sum_i d(s_0,s_i)^{-2}z_i}{\sum_i d(s_0,s_i)^{-2}}.

If s0s_0 exactly matches a sample coordinate, the implementation must return or reconcile the colocated observations rather than divide by zero. Distance power, search radius, neighbor count, barriers, anisotropy, trend, duplicate samples, and extrapolation boundary are modeling choices. IDW gives a weighted average; it does not itself provide a probabilistic uncertainty model.

Kriging additionally needs a mean/trend and covariance or variogram model with stationarity assumptions appropriate to the residual process. Estimating that model from the same sparse data adds uncertainty. Cross-validation must respect clusters, transects, time, and the deployment geography.

Worked example​

import numpy as np

coordinates = np.array([[0, 0], [0, 2], [2, 0], [2, 2], [1, 3]], dtype=float)
values = np.array([10, 14, 12, 18, 17], dtype=float)
query = np.array([1, 1], dtype=float)

def idw(train_coordinates, train_values, target, power=2):
distances = np.linalg.norm(train_coordinates - target, axis=1)
exact = np.flatnonzero(distances == 0)
if len(exact):
return float(train_values[exact].mean())
weights = distances ** (-power)
return float(weights @ train_values / weights.sum())

prediction = idw(coordinates, values, query)
leave_one_out = []
for index in range(len(values)):
leave_one_out.append(idw(np.delete(coordinates, index, axis=0),
np.delete(values, index), coordinates[index]))
mae = np.mean(np.abs(np.array(leave_one_out) - values))
print(f"samples={len(values)} support=point crs=local_planar power=2")
print(f"query=(1,1) prediction={prediction:.2f} nearest_sample_distance={np.linalg.norm(coordinates - query, axis=1).min():.2f}")
print(f"validation=leave-one-out mae={mae:.2f} uncertainty_model=none extrapolation=False")

Expected output:

samples=5 support=point crs=local_planar power=2
query=(1,1) prediction=13.89 nearest_sample_distance=1.41
validation=leave-one-out mae=2.67 uncertainty_model=none extrapolation=False

The leave-one-out score checks arithmetic on this tiny fixture. Nearby held-out samples share spatial context, so it can be optimistic for prediction into a separated region.

Limitations and common mistakes​

  • Interpolating counts or categories as if they were continuous measurements can be meaningless.
  • Point measurements and area averages have different support; mixing them creates a change-of-support problem.
  • Convex-hull extrapolation is not interpolation and should be flagged or masked.
  • A visually smooth surface is not evidence of low error.
  • Validation residuals, quantiles, kriging variances, and full predictive intervals have different interpretations.

Practice​

Add a barrier that makes two geometrically close samples disconnected. Define a domain-aware distance, a holdout design, and an uncertainty summary before comparing it with Euclidean IDW.

Next steps​

Next, model an outcome with covariates while diagnosing dependent residuals in spatial regression.

Primary sources​

Checked 2026-10-18: D. Shepard, A Two-Dimensional Interpolation Function for Irregularly-Spaced Data; SciPy 1.18, RBFInterpolator assumptions and scaling; OGC, Topic 2—Referencing by Coordinates.