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

mccorb lists at mcbsystems.us
Fri Jan 27 11:25:43 PST 2017


Even,

I agree but the call to  ComputeRasterMinMax() contains nodata values for
the min. It doesn't do the downcast correctly.

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=unsubscribe_by_code&node=5305118&code=bGlzdHNAbWNic3lzdGVtcy51c3w1MzA1MTE4fDE0Nzc3NDEwNzU=>
> .
> NAML
> <http://osgeo-org.1560.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://osgeo-org.1560.x6.nabble.com/java-Dataset-GetRasterBand-i-ComputeRasterMinMax-not-working-for-float-data-tp5305118p5305127.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170127/0d9e4589/attachment.html>


More information about the gdal-dev mailing list