Kriging Contour Mapper for Scattered Points
Operator: Abdulla Al Fahad. How tools are built and checked
Scattered measurements describe a surface only at the places someone stood. To contour a groundwater level, a soil concentration or an ore grade you need a rule for the values in between, and kriging is the rule that uses the data's own spatial correlation instead of a fixed power of distance. It gives an estimate at every grid cell and, unlike inverse distance weighting, a variance that says how far each estimate can be trusted.
The page reads x, y and value columns from a CSV or XLSX file, builds an experimental variogram, fits a spherical, exponential, Gaussian or linear model by weighted least squares, and grids by ordinary kriging from a local neighbourhood of nearby points. The fitted model is printed under the map, because a variogram fit is a judgement and anyone reading the map should be able to see what it was.
Key features
- Experimental variograms over 3 to 60 lag bins, optionally directional with an angle and a tolerance
- Spherical, exponential, Gaussian and linear models fitted by Cressie-weighted least squares, with an optional fixed nugget and a note when the range runs away
- Editable nugget, partial sill, range, anisotropy ratio and major axis angle, after the fit
- Ordinary kriging from the nearest 2 to 64 points, with a search radius and an optional per-octant cap, or inverse distance weighting over the same neighbourhood
- Leave-one-out cross-validation: mean error, RMSE, MAE, correlation and the mean and root-mean-square standardised error
- Contour map with filled bands, labelled levels, optional data points and a toggle to the kriging variance
- Longitude and latitude columns projected to UTM metres with proj4, so distances in the variogram are real distances
- Exports: grid CSV, ESRI ASCII grid, GeoTIFF, contours as GeoJSON and DXF, and the volume above and below a plane
How the variogram, neighbourhood and grid are built
The table needs a header row and three columns: x, y and the measured value. The page guesses the columns from their names (x, lon, easting, y, lat, northing, z, value, elevation, depth, grade, conc), and you can change them. Cells may use thousands separators, currency signs or accounting negatives. Rows missing any of the three numbers are skipped and counted, points sharing identical coordinates are averaged into one, and up to 5,000 distinct points are used so that every estimate can search all of them.
With the longitude-latitude box ticked, the columns are projected to the UTM zone of the points' mean position, and the GeoTIFF and GeoJSON then carry that zone's EPSG code. Without it, the numbers are used as given and the GeoTIFF has no coordinate system code. A value in the longitude column outside -180 to 180, or a latitude outside -80 to 84, stops the run with a hint that the columns may be swapped.
The grid is square. You choose 10 to 300 columns; rows follow from the extent, and a grid may hold at most 90,000 cells. Padding extends the extent by a percentage of its size. Cells with fewer than the minimum number of points inside the search radius stay empty and are counted.
ESRI ASCII and GeoTIFF export need square cells, which the grid always has. The GeoTIFF is 32-bit float with -9999 for empty cells, with its origin at the top-left corner of the cell grid. The DXF holds contour outlines as polylines, one layer per level, with the level as the vertex elevation.
How it works
Semivariance for a lag bin is half the mean squared difference between pairs whose separation falls in it. Models follow the GSLIB convention: the spherical reaches its sill at the range, while the exponential and Gaussian reach 95 percent of it there. The fit minimises Σ N_j (γ_j - γ(h_j))² / γ(h_j)² by Nelder-Mead from four starting ranges, with the three parameters kept non-negative by squaring and the range capped at five times the longest lag.
An ordinary kriging estimate at a cell solves the system Γ λ + μ 1 = γ0, Σ λ = 1 for the nearest points, with Γ the matrix of model semivariances between them and γ0 the vector to the cell. The estimate is Σ λ z and the kriging variance is Σ λ γ0 + μ. A matrix this small is solved by elimination with pivoting; the page never forms the full N by N system, which is why it can work with thousands of points.
Anisotropy is a geometric transform: separation is rotated to the major axis and the minor-axis component is divided by the ratio before the model sees it. The octant option keeps at most a given number of points from each of eight directions so a cluster on one side cannot hide the other sides.
Cross-validation removes each point in turn and predicts it from its neighbours. The mean standardised error should be near 0 and the root-mean-square standardised error near 1 when the variance model is honest; values well below 1 mean the kriging variance is too pessimistic for those data.
Common use cases
- A hydrogeologist contours 85 water levels measured over two days and uses the kriging variance map to decide where to drill the next monitoring well.
- An environmental consultant maps a lead concentration from 300 soil samples and exports the contours as GeoJSON for a site plan.
- A mine geologist fits directional variograms along and across a bedding trend to see whether the two ranges differ, then enters the ratio as anisotropy.
- A surveyor grids spot heights at 100 columns across the site, then computes cut and fill volumes against a design plane at 110.
- A student checks that setting the nugget to zero makes the surface pass exactly through every sample.
How to use this tool
- Choose a file or paste a table, then check the x, y and value columns, and tick the box if x and y are longitude and latitude.
- Compute the variogram: pick the number of bins and the maximum lag, then fit a model and look at the curve against the points.
- Adjust the nugget, partial sill or range by hand if the curve misses the points you care about, and add anisotropy if a directional variogram showed it.
- Set the grid columns, the number of neighbours and a search radius, then press Grid the surface.
- Press Cross-validate and compare its RMSE with the inverse-distance option on the same neighbourhood.
- Change the contour intervals, then download the grid, GeoTIFF or contour files.
Example
Load synthetic survey (140 points over 1,000 by 800 units: a gentle slope plus two hills, with noise of up to 0.4 units)
Columns x, y, z. 15 lag bins out to 600, Gaussian model, 16 nearest points, 100 columns.What the page reports
Fit: nugget 0.077, partial sill 44.13, range 457.5, from 6,697 point pairs. Grid 100 by 79, estimates from 100.9 to 126.0, kriging variance up to 3.14. Cross-validation: RMSE 0.339, mean error 0.017, RMS standardised error 0.85, correlation 0.998; inverse distance (power 2) on the same neighbours gives RMSE 1.35.Tips for best results
- Set the maximum lag to about half the extent. Pairs far beyond that mix distant regions and flatten the variogram.
- If the fit warns that the range ran to its limit, the data have no sill at that lag; try a linear model or a larger maximum lag.
- Smooth data such as elevations favour a Gaussian model, while noisy measurements with abrupt changes favour a spherical or exponential one.
- A search radius shorter than the range leaves cells empty far from data instead of extrapolating, which is often the honest result.
- Fix the nugget when you know the measurement error, for example from duplicate samples at one location; the fit then spends its freedom on sill and range.
- Run cross-validation before gridding a large area, and compare the root-mean-square standardised error with 1 to judge the variance model.
Common pitfalls
Kriging variance describes the model, not the ground. It depends only on where the points are and on the variogram, so a surface with a confident-looking variance map can still be wrong where the data are biased.
Ordinary kriging assumes a locally constant mean. A strong regional trend should be removed first or the surface will fade towards the local average at the edges; universal kriging is not offered.
Variogram fitting with few pairs is unstable. Bins with fewer than a few dozen pairs carry little weight and the model can swing between bins.
A grid is an interpolation, not a measurement: contours inside areas without samples show the model's behaviour there.
Common errors and how to fix them
- Fewer than 3 lag bins have pairs, so a model cannot be fitted.
- Use a larger maximum lag or fewer bins; this happens when the maximum lag is shorter than most point spacings.
- All semivariances are zero: the values do not vary.
- Check that the value column is the one you meant. A constant column has nothing to krige.
- Longitude must be -180 to 180 and latitude -80 to 84 for a UTM projection.
- The x and y columns are probably swapped, or the coordinates are already projected; untick the longitude and latitude box.
- That grid has 96,000 cells; the limit is 90,000.
- Use fewer columns, or crop a long thin extent; rows follow from the extent and the cell size.
- 6,200 distinct points. This tool uses up to 5,000 so every estimate can search all of them.
- Thin the data, for example by averaging into 2 m blocks, before loading.
Best practices
- Print the model with every map you share: model type, nugget, partial sill, range, anisotropy, neighbours and radius are listed under the contour plot.
- Compare kriging with inverse distance on the same neighbourhood; if cross-validation shows no gain, the simpler method is enough.
- Look at the variogram points before the fit line, and trust the points.
Checking the kriging against independent calculations
A five-point example (spherical model, nugget 1, sill 2, range 3.5) was solved by a separate Gaussian elimination written in plain Python, and the page's estimates and kriging variances agree with it to 1e-15 at four test locations; the weights sum to 1 and the estimate at a data point reproduces its value with zero variance.
That last property holds for ordinary kriging whatever the nugget, because the semivariance of a point with itself is taken as zero. The surface passes through every sample; the nugget enters only through the neighbours' weights and the variance.
Reading the cross-validation statistics
RMSE and MAE are in the units of the value and compare directly with inverse distance weighting. Mean error near zero says the surface is not biased on average. The standardised errors divide each error by its kriging standard deviation, so a root-mean-square value of 0.85 as in the example means the model's variance overstates the real error slightly, while a value of 2 would mean the variance badly understates it.
Frequently asked questions
Why is the surface exact at the samples when I add a nugget?
Ordinary kriging as implemented here treats the semivariance between a point and itself as zero, so a data point is its own best estimate. A nugget only widens the variance away from samples. If you want smoothing of noisy data, average duplicates or noisy neighbours first.
How many points can it handle?
Up to 5,000 distinct points and 90,000 grid cells. Every estimate uses only its nearest points, so the cost grows with the neighbour count and the number of cells, not with the cube of the number of points.
What is the difference between the range of an exponential and a spherical model?
The spherical model reaches its full sill at the range. The exponential and Gaussian reach 95 percent of it there, the GSLIB convention, so a fitted exponential range is about three times its scale parameter.
Can I use it for elevations from a total station?
Yes, with projected coordinates in metres or feet. Surfaces with sharp breaks such as a road crest or a stream bank are poorly served by any variogram model; use breaklines in survey software for those.
Which coordinate system do the exports use?
UTM for the zone of the data when you ticked longitude and latitude, with the EPSG code written into the GeoTIFF and GeoJSON. For projected input the GeoTIFF carries no code, so assign one in your GIS when you open it.