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

mccorb lists at mcbsystems.us
Fri Jan 27 11:54:38 PST 2017


If you like I can upload the file and send you a google drive link if you
give me the email you want to receive it from.

Thanks,

On Fri, Jan 27, 2017 at 1:34 PM, Even Rouault-2 [via OSGeo.org] <
ml-node+s1560n5305129h58 at n6.nabble.com> wrote:

> 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] <
>
> >
>
> > [hidden email] <http:///user/SendEmail.jtp?type=node&node=5305129&i=0>>
> 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=bGlzdHNAbWNic3lzdGVtcy51c3w1Mz
> A1MTE4fDE0Nz
>
> > > c3NDEwNzU=> .
>
> > > NAML
>
> > > <http://osgeo-org.1560.x6.nabble.com/template/
> NamlServlet.jtp?macro=macro_
>
> > > viewer&id=instant_html%21nabble%3Aemail.naml&base=
> nabble.naml.namespaces.B
>
> > > asicNamespace-nabble.view.web.template.NabbleNamespace-
> nabble.view.web.tem
>
> > > plate.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.
> naml-i
>
> > > nstant_emails%21nabble%3Aemail.naml-send_instant_
> email%21nabble%3Aemail.na
>
> > > ml>
>
> > --
>
> > View this message in context:
>
> > http://osgeo-org.1560.x6.nabble.com/java-Dataset-
> GetRasterBand-i-ComputeRas
>
> > terMinMax-not-working-for-float-data-tp5305118p5305127.html Sent from
> the
>
> > GDAL - Dev mailing list archive at Nabble.com.
>
>
>
>
>
> --
>
> Spatialys - Geospatial professional services
>
> http://www.spatialys.com
>
> _______________________________________________
> gdal-dev mailing list
> [hidden email] <http:///user/SendEmail.jtp?type=node&node=5305129&i=1>
> 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-tp5305118p5305129.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-tp5305118p5305131.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/fb50d8cb/attachment.html>


More information about the gdal-dev mailing list