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

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


Driver: GTiff/GeoTIFF
Files: elevation.tif
Size is 7195, 5531
Coordinate System is:
PROJCS["NAD_1983_UTM_Zone_17N",
    GEOGCS["NAD83",
        DATUM["North_American_Datum_1983",
            SPHEROID["GRS 1980",6378137,298.2572221010002,
                AUTHORITY["EPSG","7019"]],
            AUTHORITY["EPSG","6269"]],
        PRIMEM["Greenwich",0],
        UNIT["degree",0.0174532925199433],
        AUTHORITY["EPSG","4269"]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",-81],
    PARAMETER["scale_factor",0.9996],
    PARAMETER["false_easting",500000],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AUTHORITY["EPSG","26917"]]
Origin = (543011.291966574150000,4153822.939761789500000)
Pixel Size = (28.143460884725201,-28.143460884725226)
Metadata:
  AREA_OR_POINT=Area
  DataType=Generic
Image Structure Metadata:
  COMPRESSION=LZW
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (  543011.292, 4153822.940) ( 80d30'47.51"W, 37d31'49.36"N)
Lower Left  (  543011.292, 3998161.458) ( 80d31'19.22"W, 36d 7'37.88"N)
Upper Right (  745503.493, 4153822.940) ( 78d13'22.19"W, 37d29'55.39"N)
Lower Right (  745503.493, 3998161.458) ( 78d16'22.86"W, 36d 5'49.55"N)
Center      (  644257.392, 4075992.199) ( 79d22'57.31"W, 36d49' 7.69"N)
Band 1 Block=128x128 Type=Float32, ColorInterp=Gray
    Computed Min/Max=-340282306073709650000000000000000000000.000,2282.341
  NoData Value=-3.4028229999999999e+038



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-tp5305118p5305130.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/cef4c65f/attachment-0001.html>


More information about the gdal-dev mailing list