[QGIS-Developer] nodata and raster calc
Tim Sutton
tim at kartoza.com
Sun Feb 10 21:56:03 PST 2019
Hi
> On 11 Feb 2019, at 04:11, Nyall Dawson <nyall.dawson at gmail.com> wrote:
>
> Hey all,
>
> I'm seeking some feedback on whether our current handling of nodata
> pixels in the raster calculator is correct, or (my suspicion) annoying
> and limiting.
>
> Currently, we treat nodata pixels the same as a "NULL" value in SQL --
> so ANY function or operation with nodata as an input results in a
> nodata output.
>
> This means:
>
> - nodata + 1 = nodata
> - nodata * 1 = nodata
> - nodata AND 1 = nodata
> - nodata OR 1 = nodata
Yes this was by design. IIRC Marco Hugentobler implemented the raster calculator under contract to me a long time ago and we discussed this use case in particular. Our view was that nodal acts as a mask. To work around the case where you want to treat nodata as zero you would need to reclassify the raster to recode null to zero and then perform your calculation. To support your use case couldn’t we just add a zero_if_null(raster) function that you can wrap around layer references? Or use your coalesce idea below - though maybe zero_if_null will be more intuitive?
Regards
Tim
>
> To me this is a mistake. I don't think we should treat nodata the same
> as NULL, and I think for rasters then "nodata OR 1" should return 1.
>
> The end result of the current behaviour is that ANY nodata input
> blocks processing of that pixel. So you can't do something like take
> two raster files, and create an output showing where either input has
> a 1 value (which I would expect raster1 at 1 OR raster2 at 1 to do).
>
> Otherwise, we need to have some concept of "coalesce" in the raster
> calc. So then at least you could do:
>
> coalesce(raster1 at 1, 0) OR coalesce(raster at 1, 0) ....
>
>
> Thoughts?
>
> Nyall
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
—
Tim Sutton
Co-founder: Kartoza
Ex Project chair: QGIS.org
Visit http://kartoza.com <http://kartoza.com/> to find out about open source:
Desktop GIS programming services
Geospatial web development
GIS Training
Consulting Services
Skype: timlinux
IRC: timlinux on #qgis at freenode.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20190211/a323a95e/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: KartozaNewLogoThumbnail.jpg
Type: image/jpeg
Size: 6122 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20190211/a323a95e/attachment-0001.jpg>
More information about the QGIS-Developer
mailing list