Skip to content
← Back to QGIS from first project to capstone
QGIS · Part 14 of 20Intermediate· 7 min readSources

QGIS Interpolation, Density Analysis and Heatmaps

Turn scattered point values into a surface with IDW, TIN and kriging, and turn point locations into density surfaces and heatmaps.

Two different problems

InterpolationDensity analysis
InputPoints with a measured value (temperature, rainfall, elevation)Points that mark where something is (hospitals, incidents)
QuestionWhat is the value between my sample points?How concentrated are the points?
OutputA continuous surface of the measured variableA surface of how many points per unit area

Pick the method by the question. Interpolating the count of hospitals, for example, is usually meaningless, while density is the right way to show where they cluster.

Data used

  • Landsat 8 surface temperature ST_B10 for 29 March 2025 (path 144 row 051). It is already a surface temperature product, so you convert the integers to Celsius and do not need to calculate it from radiance.
  • hospitals points from Q11.

1. Prepare the surface temperature

The Landsat Collection 2 surface temperature band stores Kelvin as integers.

temperature (K) = DN * 0.00341802 + 149.0
temperature (C) = temperature (K) - 273.15

In the Raster Calculator, with the layer named L8_ST:

("L8_ST@1" * 0.00341802 + 149.0) - 273.15

Save as lst_c.tif. Cells with DN of 0 are NoData and come out at about -124, so set 0 as the NoData value on the input first (Layer Properties > Transparency > Additional no data value).

Clip to an area around Bengaluru (Part 1).

Land surface temperature map in Celsius
Figure 14.1. Land surface temperature map in Celsius

2. Create sample points

Real interpolation starts with measurements at points. We make them from the raster, so we can compare the result against the true surface.

  1. Processing > Random Points in Extent. Extent: the clip area. Number of points: 300. Minimum distance: 500. CRS: EPSG:32643.
  2. Processing > Sample Raster Values. Input: the random points. Raster: lst_c. Output column prefix: temp. A column temp1 appears.
  3. Open the attribute table and remove any rows with NULL temp1 (Select by Expression: "temp1" IS NULL, then delete).
  4. Set aside about 20% for testing. Add an integer field holdout with the Field Calculator: if(rand(1,5) = 1, 1, 0). Then split into train (where holdout = 0) and test (where holdout = 1) with Extract by Expression.
Random sample points over the temperature map
Figure 14.2. Random sample points over the temperature map

3. IDW interpolation

Inverse distance weighting estimates a value as a weighted average of nearby samples. Closer points count more.

  1. Processing > IDW Interpolation.
  2. Input layer: train. Interpolation attribute: temp1. Click the plus to add it.
  3. Distance coefficient P: start with 2.
  4. Extent: from the clip area. Output raster size: set Pixel size to 100.
  5. Run, and style with the same ramp as the original surface.

Raise P and the surface hugs the nearest sample. Lower P and it smooths. IDW cannot produce values beyond the sample minimum and maximum, and it makes small circular bumps around points.

IDW result
Figure 14.3. IDW result

4. TIN interpolation

A TIN (triangulated irregular network) joins the sample points into triangles, and interpolates linearly inside each triangle.

  1. Processing > TIN Interpolation.
  2. Input: train, attribute temp1, with Use Z coordinate for the interpolation off.
  3. Method: Linear. Extent and pixel size as before.

A TIN passes exactly through each sample and gives hard edges at the triangle boundaries. It does not extrapolate beyond the points' convex hull.

5. Kriging

Kriging uses a model of how similar values are at different distances (a variogram), and gives the best linear estimate under that model, along with an uncertainty.

QGIS does not include kriging in its core Processing tools, so use one of these:

  • GRASS: v.krige, which needs R with the gstat package.
  • SAGA: Ordinary Kriging, with a variogram from SAGA's Variogram tool, if your QGIS includes SAGA (the 3.44 install used here does not).

The usual workflow is:

  1. Plot the empirical variogram of the training values.
  2. Fit a model (spherical, exponential or Gaussian) and read its nugget, sill and range.
  3. Run ordinary kriging with the fitted model.
  4. Map both the estimate and the kriging variance.

Kriging is only as good as the variogram, and a poor fit gives a poor surface. For a tutorial, IDW and TIN are enough, and kriging can be a follow-up.

6. Compare and check the result

Compare each method against the held-out test points.

  1. Run Sample Raster Values on the test points for each interpolated surface, with prefixes idw_ and tin_.
  2. In the Field Calculator, add err_idw as "idw_1" - "temp1" and err_tin as "tin_1" - "temp1".
  3. Use Basic Statistics for Fields on each error column. The mean error (bias) and the root mean square error (RMSE) are the numbers to compare. RMSE is the square root of the mean of the squared errors, which you can compute as sqrt(mean("err_idw" * "err_idw")) in the Statistics Panel or a spreadsheet.

The method with lower RMSE on points it never saw is the better fit for this data. In the tutorial run, IDW and TIN gave RMSE values within about 0.2 degrees of each other, around 2.3 to 2.5 degrees Celsius, and which one came out ahead changed with the random sample. That is a useful result in itself: with 230 samples over 30 km, the choice of method matters less than the sampling. The pattern will differ with another study area.

Error statistics for the two methods
Figure 14.4. Error statistics for the two methods

7. Density analysis and heatmaps

Kernel density (heatmap)

  1. Processing > Heatmap (Kernel Density Estimation).
  2. Point layer: hospitals.
  3. Radius: 3000 m. The radius sets how far each point's influence spreads, so it controls the smoothness.
  4. Pixel size: 50 m.
  5. Kernel shape: Quartic (biweight) is a common default.
  6. Optional: Weight from field, if each point carries a count.
  7. Run. Style with a heat-style ramp (for example Magma or Inferno), with the lowest values transparent.
Hospital heatmap over a basemap
Figure 14.5. Hospital heatmap over a basemap

Try 1500 m and 6000 m for the radius. A small radius shows local peaks, and a large one shows broad regions. There is no single right radius, so choose one that matches the scale of the question.

Live heatmap renderer

For a quick look without producing a raster, set the layer's Symbology to Heatmap. It is for display only, so use the Heatmap tool when you need the numbers.

Point density in a grid

  1. Create a hexagon or square grid (Processing > Create Grid).
  2. Run Count Points in Polygon (Q11).
  3. Divide the count by cell area to get points per square kilometre.

A grid is easier to explain and compare than a smoothed surface. It depends on the cell size and the position of the grid, so try a different size to see how stable the pattern is.

Common mistakes

  • Interpolating something that is a count of events and not a measured field.
  • Using too few samples, or only samples clustered in one place.
  • Judging an interpolation by how smooth it looks.
  • Testing against the same points used to build it.
  • Picking a heatmap radius without trying others.
  • Running interpolation in a geographic CRS, where distances are in degrees.

Key takeaways