[gdal-dev] java Dataset.GetRasterBand(i).ComputeRasterMinMax not working for float data

Even Rouault even.rouault at spatialys.com
Fri Jan 27 11:33:10 PST 2017


On vendredi 27 janvier 2017 12:25:43 CET mccorb wrote:
> Even,
> 
> I agree but the call to  ComputeRasterMinMax() contains nodata values for
> the min. It doesn't do the downcast correctly.

What does gdalinfo -mm report ?

> 
> thanks,
> 
> On Fri, Jan 27, 2017 at 12:38 PM, Even Rouault-2 [via OSGeo.org] <
> 
> ml-node+s1560n5305119h48 at n6.nabble.com> wrote:
> > On vendredi 27 janvier 2017 11:15:59 CET mccorb wrote:
> > > I have a geotiff image with float data (GDT_Float32). When I read a tile
> > 
> > I
> > 
> > > have to case the nodata value to float to make it compare otherwise it
> > > 
> > > doesn't...here is a reduced snippet of my code
> > > 
> > > 
> > > 
> > > Double[] d = new Double[1];
> > > 
> > > rb.GetNoDataValue(d);
> > > 
> > > double noDataVal = d[0];
> > > 
> > > ...
> > > 
> > > if(rasterBandDataType == gdalconstConstants.GDT_Float32)
> > > 
> > > {
> > > 
> > > float[] array = new float[(rect.height * rect.width)];
> > > 
> > > int retVal = rb.ReadRaster(rect.x, rect.y, rect.width, rect.height,
> > > 
> > > rasterBandDataType, array);
> > > 
> > > * float noDataValCast = (float) noDataVal;*
> > > 
> > > for(int i = 0; i < array.length; i++)
> > > 
> > > {
> > > 
> > > if(noDataValCast == buff[i])
> > > 
> > > array[i] = Double.NaN;
> > > 
> > > else
> > > 
> > > array[i] = (scale * buff[i]) + offset;
> > > 
> > > }
> > > 
> > > }
> > > 
> > > 
> > > 
> > > If I don't cast the noDataVal to a float then the value in the returned
> > > 
> > > array doesn't equal the noData value
> > > 
> > > returned from the raster band.
> > > 
> > > 
> > > 
> > > It seems as though the ComputeRasterMinMax call has the same issue as I
> > 
> > was
> > 
> > > having before I did the casting. I definitely want to use this method it
> > > 
> > > because it is much faster than pulling the tiles and processing them
> > 
> > myself.
> > 
> > 
> > 
> > All of that is more or less expected given that GetNoDataValue() and
> > ComputeRasterMinMax() return double values. So if you compare to float
> > directly, the float get promoted to double (and the double isn't strictly
> > equal to the initial pixel value), and tiny precision issues appear.
> > Downcasting to float as you did is the way to go.
> > 
> > 
> > 
> > Even
> > 
> > 
> > 
> > --
> > 
> > Spatialys - Geospatial professional services
> > 
> > http://www.spatialys.com
> > 
> > _______________________________________________
> > gdal-dev mailing list
> > [hidden email] <http:///user/SendEmail.jtp?type=node&node=5305119&i=0>
> > https://lists.osgeo.org/mailman/listinfo/gdal-dev
> > 
> > ------------------------------
> > If you reply to this email, your message will be added to the discussion
> > below:
> > http://osgeo-org.1560.x6.nabble.com/java-Dataset-GetRasterBand-i-> > ComputeRasterMinMax-not-working-for-float-data-tp5305118p5305119.html
> > To unsubscribe from java Dataset.GetRasterBand(i).ComputeRasterMinMax not
> > working for float data, click here
> > <http://osgeo-org.1560.x6.nabble.com/template/NamlServlet.jtp?macro=unsubs
> > 
cribe_by_code&node=5305118&code=bGlzdHNAbWNic3lzdGVtcy51c3w1MzA1MTE4fDE0Nz
> > c3NDEwNzU=> .
> > NAML
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170127/d9ccf200/attachment-0001.html>


More information about the gdal-dev mailing list