Opened 13 months ago

Closed 13 months ago

Last modified 13 months ago

#6578 closed defect (fixed)

Mask set to nodata for values near nodata

Reported by: Mike Toews Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: 2.1.0
Severity: normal Keywords:
Cc:

Description

This issue is partially described for QGIS here http://hub.qgis.org/issues/15202

I've attached a Float32 raster calculated with gdal_calc.py (prior to [34037]), which has a nodata of 1.175494351E-38 and at least one pixel with a value of 0.0. ArcGIS correctly distinguishes between the 0.0 value and nodata value pixels, but QGIS and GDAL's GetMaskBand consider both of these as nodata.

from osgeo import gdal
ds = gdal.Open('C.tif')
b = ds.GetRasterBand(1)
mb = b.GetMaskBand()
print(mb.ReadAsArray())

 [[  0 255 255 255]
  [255   0 255 255]
  [255 255 255 255]]

The expected result should be:

[[255 255 255 255]
 [255   0 255 255]
 [255 255 255 255]]

Or with numpy as a masked array:

import numpy as np
ar = np.ma.masked_equal(b.ReadAsArray(), b.GetNoDataValue())
print(repr(ar))

masked_array(data =
 [[0.0 -0.100000023842 -0.200000047684 -0.299999952316]
 [-0.400000095367 -- -0.599999904633 -0.699999809265]
 [-0.800000190735 -0.89999961853 -1.0 -1.10000038147]],
             mask =
 [[False False False False]
 [False  True False False]
 [False False False False]],
       fill_value = 1.17549e-38)

Attachments (1)

C.tif (223 bytes) - added by Mike Toews 13 months ago.

Download all attachments as: .zip

Change History (5)

Changed 13 months ago by Mike Toews

Attachment: C.tif added

comment:1 Changed 13 months ago by Even Rouault

This is due to the following test :

// Test if 2 floating point values match. Useful when comparing values
// stored as a string at some point. See #3573, #4183, #4506
#define ARE_REAL_EQUAL(dfVal1, dfVal2) \
 (dfVal1 == dfVal2 || fabs(dfVal1 - dfVal2) < 1e-10 || (dfVal2 != 0 && fabs(1 - dfVal1 / dfVal2) < 1e-10 ))

I guess that special cases should be made for FLT_MIN and DBL_MIN

comment:2 Changed 13 months ago by Even Rouault

Resolution: fixed
Status: newclosed

In 34608:

Nodata comparison: fix test when nodata is FLT_MIN or DBL_MIN (fixes #6578)

comment:3 Changed 13 months ago by Even Rouault

In 34609:

Nodata comparison: fix test when nodata is FLT_MIN or DBL_MIN (fixes #6578)

comment:4 Changed 13 months ago by Even Rouault

Fix in 2.1 branch post 2.1.1RC2

Note: See TracTickets for help on using tickets.