[gdal-dev] gdal_calc not ignoring NoData values?

Spencer Gardner spencergardner at gmail.com
Mon Jun 12 07:40:54 PDT 2017


I have two integer rasters, A and B, with the same dimensions and cell
sizes. I want to compare each cell in A with each cell in B and keep the
maximum value. In cases where both have nodata, I want the result to be
nodata. In cases where one is nodata, I want the result to be the integer
value of the one with data.

   Raster A                    Raster B
|   1     |   1     |             |   3     |   1     |
|   1     |nodata|             |nodata|   3     |
|nodata|   1     |             |nodata|nodata|
|nodata|   4     |             |nodata|   1     |

--------------------------------------------
                Desired result
               |   3     |   1     |
               |   1     |   3     |
               |nodata|   1     |
               |nodata|   4     |

've tried combining them in many different ways using gdal_calc but somehow
I can't seem to get the answer I'm looking for. My first instinct was to
use numpy.fmax since the documentation states that the NaN value is
ignored. But this calculation

--calc "numpy.fmax(A,B)"

only gives me the results I want in cells where both datasets have a value.
A nodata in either results in nodata in the result:

              numpy.fmax result
               |   3     |   1     |
               |nodata|nodata|
               |nodata|nodata|
               |nodata|   4     |

Perhaps I'm confused about how nodata translates to NaN in numpy? What is a
straightforward way to accomplish this with gdal_calc?

Thanks for any help,
Spencer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170612/67f484f0/attachment.html>


More information about the gdal-dev mailing list