Kriging (NNGP) interpolation layer (CONNECTIONTYPE kriging)#7535
Kriging (NNGP) interpolation layer (CONNECTIONTYPE kriging)#7535hlherrera wants to merge 3 commits into
Conversation
abdd6db to
7c10966
Compare
Adds an ordinary-kriging interpolation layer implemented as a localized Nearest-Neighbor Gaussian Process: each output pixel is predicted from its m nearest samples, so cost scales with the neighbour count rather than the sample count. Emits two byte bands (predictive mean and the kriging standard error), selectable via PROCESSING "BANDS=n". The numeric core lives in src/kriging_nngp.h (pure C) and plugs into the existing interpolation framework alongside IDW and kernel density. Tunable through KRIGING_MODEL/TYPE/NEIGHBORS/RANGE/SILL/NUGGET.
Adds the "kriging" keyword to maplexer.l and regenerates maplexer.c with the project's flex invocation (flex --nounistd -Pmsyy -i). The large maplexer.c diff is the usual flex DFA-table reshuffle from introducing a new keyword.
Adds msautotest/gdal/kriging.map exercising CONNECTIONTYPE kriging, the two-band (mean + std dev) output and the PROCESSING knobs over a small self-contained 16-point CSV. The surface is rendered by the vendored AGG with no fonts, so the expected images are platform-independent.
7c10966 to
ec5524e
Compare
|
Thanks, @hlherrera. The more generic parts of this PR seem good to me. I've no idea for the To add this feature you'll also need to add a docs page to https://github.com/MapServer/MapServer-documentation/. |
|
Thanks @geographika. AI helped, but I worked through the implementation myself and I'm comfortable maintaining it. It's small: a dependency-free numeric core (kriging_nngp.h) with a unit test, plus thin MapServer glue (kriging.c) for the per-pixel solve over the m nearest samples. The msautotest case compares against committed expected images for regression coverage. Docs: opened MapServer-documentation#1093, same style as the IDW page, with the NZ rainfall example and uncertainty band. |
Summary
Adds a new interpolation layer type,
CONNECTIONTYPE kriging, implementing ordinary kriging as a localized Nearest-Neighbor Gaussian Process (NNGP). Like the existing IDW and Kernel-Density layers, it turns a point/vector source layer into a Raster surface and it additionally produces a second band with the Kriging standard error (predictive uncertainty), which IDW cannot.Kriging and Gaussian-Process regression are the same method; the NNGP formulation (Datta et al., 2016, after Vecchia, 1988) predicts each output pixel from only its m nearest samples, so per-pixel cost scales with the neighbour count rather than the total sample count, it stays fast as the sample set grows.
How it works
src/interpolation.c), fed by a source vector layer throughCONNECTION(= the source layer'sNAME), with the sample value taken from that layer'sSTYLE SIZE [attribute]exactly as IDW does.src/kriging_nngp.h(pure C, libc only): a uniform-grid spatial index for exact k-NN, a small dense LU solve per neighbourhood, and the ordinary/simple kriging predictor + variance.GDT_Bytebands1= predictive mean,2= predictive std dev selected withPROCESSING "BANDS=n"(default band 1).PROCESSING keys
KRIGING_MODELEXPONENTIAL(Matérn) ·GAUSSIAN·SPHERICALEXPONENTIALKRIGING_TYPEORDINARY(unknown local mean) ·SIMPLEORDINARYKRIGING_NEIGHBORS16KRIGING_RANGEKRIGING_SILLKRIGING_NUGGET0= exact interpolation,>0= smoothing0Commits
kriging.c,kriging_nngp.h, theMS_KRIGINGconnectiontype, dispatch + an N-band output path ininterpolation.c, the== MS_IDWguards mirrored inmapraster.c/maprasterquery.c, and CMake.krigingtomaplexer.land regeneratesmaplexer.cwith the project's invocationflex --nounistd -Pmsyy -i. The largemaplexer.cdiff is the usual flex DFA-table reshuffle from adding a keyword (this file is excluded from clang-format in.pre-commit-config.yaml).msautotest/gdal/kriging.mapover a small, self-contained 16-point CSV, exercising the connectiontype, both bands, and the PROCESSING knobs.Testing
kriging.cand the wiring compile with no warnings, and the new sources pass clang-format 15.0.7.msautotest/gdal/kriging.maprenders and matches the committed expected images. The surface is drawn by the vendored AGG with no fonts, so the expected PNGs are platform-independent.Notes for reviewers
krigingis now a reserved mapfile keyword (likeidw), so a layer literally namedkrigingwould need quoting.