# Spatial Interpolation

Published in

6 min readAug 31, 2024

Implement spatial interpolation using Python exclusively, without relying on ArcGIS software.

- Perform multiple interpolation techniques on a set of data points
- Extract interpolated values at designated locations without original samples

Interpolation is a technique for estimating values at unsampled locations by utilizing data from known, sampled points within a given area or phenomenon. This chapter will delve into three distinct interpolation approaches:

- Thiessen polygons, also known as Voronoi diagrams
- K-nearest neighbors (KNN)
- Kriging

Load libraries

`# Import modules`

import geopandas as gpd

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

from pykrige.ok import OrdinaryKriging

import rasterio

import rasterio.mask

from rasterio.plot import show

from rasterio.transform import Affine

from scipy.spatial import Voronoi, voronoi_plot_2d

from shapely.geometry import box

from shapely.geometry import Polygon, Point

from sklearn.gaussian_process import GaussianProcessRegressor

from sklearn.metrics import r2_score

from sklearn.model_selection import train_test_split

from sklearn.neighbors import KNeighborsRegressor

`# Load data`

# County boundaries

counties = gpd.read_file("sf_bay_counties/sf_bay_counties.shp")

# Rainfall measurement "locations"

# Modified by author by clipping raster to San Francisco Bay Area, generating random points, and extracting…