From 2b0b1c5bc941ff67e6fa9d14a52bfcd9cd031401 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 24 Jan 2025 18:07:54 +0100 Subject: [PATCH] Warper: add runtime warning when value changed to avoid colliding with dstnodata --- alg/gdalwarper.h | 2 ++ alg/gdalwarpkernel.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/alg/gdalwarper.h b/alg/gdalwarper.h index 15eceb561022..f3dd6408d011 100644 --- a/alg/gdalwarper.h +++ b/alg/gdalwarper.h @@ -463,6 +463,8 @@ class CPL_DLL GDALWarpKernel GWKTieStrategy eTieStrategy; + bool bWarnedAboutDstNoDataReplacement = false; + /*! @endcond */ GDALWarpKernel(); diff --git a/alg/gdalwarpkernel.cpp b/alg/gdalwarpkernel.cpp index 911a620e629f..527c15580e51 100644 --- a/alg/gdalwarpkernel.cpp +++ b/alg/gdalwarpkernel.cpp @@ -1561,6 +1561,19 @@ inline void AvoidNoData(const GDALWarpKernel *poWK, int iBand, pDst[iDstOffset], std::numeric_limits::max()); } } + + if (!poWK->bWarnedAboutDstNoDataReplacement) + { + const_cast(poWK) + ->bWarnedAboutDstNoDataReplacement = true; + CPLError(CE_Warning, CPLE_AppDefined, + "Value %g in the source dataset has been changed to %g " + "in the destination dataset to avoid being treated as " + "NoData. To avoid this, select a different NoData value " + "for the destination dataset.", + poWK->padfDstNoDataReal[iBand], + static_cast(pDst[iDstOffset])); + } } }