Even, Thank you for your help. It took me a few attempts but you were correct. I was trying to use the minimum value for a 32bit floating data set as my null data value and my number was not exact--as you suggested.
I was using: -3.4028235e+038 And needed to use: -3.4028234663852886e+038 Once I made this correction, everything worked as expected. Thanks again for your assistance, Mike --- On Wed, 4/14/10, Even Rouault <[email protected]> wrote: > From: Even Rouault <[email protected]> > Subject: Re: [gdal-dev] Compute statistis and ignoring nodata value > To: [email protected] > Cc: "Michael ODonnell" <[email protected]> > Date: Wednesday, April 14, 2010, 2:31 PM > Michael, > > ComputeStatistics() is supposed to ignore pixels whose > value is the nodata > value. I've tried the following test code to try to > reproduce your issue : > > #include <gdal.h> > > int main(int argc, char* argv[]) > { > GDALAllRegister(); > GDALDatasetH hDS = > GDALCreate(GDALGetDriverByName("GTiff"), "test.tif", 3, > 1, 1, GDT_Byte, NULL); > GDALRasterBandH hBand = > GDALGetRasterBand(hDS, 1); > char chVal; > chVal = 0; > GDALRasterIO(hBand, GF_Write, 0, 0, 1, 1, > &chVal, 1, 1, GDT_Byte, 0, 0); > chVal = 100; > GDALRasterIO(hBand, GF_Write, 1, 0, 1, 1, > &chVal, 1, 1, GDT_Byte, 0, 0); > chVal = 2; > GDALRasterIO(hBand, GF_Write, 2, 0, 1, 1, > &chVal, 1, 1, GDT_Byte, 0, 0); > GDALSetRasterNoDataValue(hBand, 100.0); > double min, max, mean, stddev; > GDALComputeRasterStatistics(hBand, FALSE, > &min, &max, &mean, &stddev, > NULL, NULL); > printf("min=%f max=%f mean=%f stddev=%f\n", > min, max, mean, stddev); > return 0; > } > > (a 3x1 dataset with pixels values being 0, 100 and 2 and > 100 set as the nodata > value) > > The results I get are : min=0.000000 max=2.000000 > mean=1.000000 > stddev=1.000000. Which is the expected values. > > I'd advise you to check that the nodata value that you set > at the band level > matches exactly the value used by the nodata pixels in the > imagery. > ComputeStatistics() uses strict equality comparison, so > even a very slight > difference might result in not recognizing the pixels as > being nodata. > > Best regards, > > Even > > Le Wednesday 14 April 2010 19:35:47 Michael ODonnell, vous > avez écrit : > > I am trying to compute and set the statistics for a > data set that I have > > created using GDAL, but the no data values are being > included. Is there a > > way to ignore the no data value when computing the > statistics. The > > documentation does not say anything about this, to the > best of my > > knowledge, and it appears to be included in my > results. Everything is > > working except that no data is included during the use > of > > ComputeStatistics. > > > > Here are the steps I am using: > > > > g_MBand->SetNoDataValue(g_nulldata2); > > g_MBand->ComputeStatistics(FALSE, &pdfMin2, > &pdfMax2, &pdfMean2, > > &pdfStdDev2, NULL, NULL); > g_InBand->SetStatistics(pdfMin2, pdfMax2, > > pdfMean2, pdfStdDev2); > > > > Thank your for your help! > > Mike > > > > > > > > _______________________________________________ > > gdal-dev mailing list > > [email protected] > > http://lists.osgeo.org/mailman/listinfo/gdal-dev > > > _______________________________________________ gdal-dev mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/gdal-dev
