[Qgis-user] Raster calculator: different,extents and nodata

Robert r.maurice.griffin at gmail.com
Wed Feb 25 12:09:46 PST 2015


Hi Michi and everyone,
Coincidentally, I also spent the better part of a whole day trying to 
figure out how to do the exact same thing yesterday with two float32 
geotiff rasters. I tried many of the suggestions in the links Nicolas 
provided to no success (and many more leads - see below). I think one of 
the issues is most of the posts related to this are addressing how to 
replace a given value with a null value for symbology, versus replacing 
null values with some real number for calculations. In ArcGIS, after you 
have extended your example raster B to the extent of raster A (which 
fills in the new area of raster B with nodata values), you can use the 
Con(IsNull) statement to transform to null values to zero for use in 
raster calculations. I have learned a lot about QGIS in the process of 
sorting this out, but do not have a ready answer for what must be a 
fairly common user context. Any help would be greatly appreciated.

Regards,
Rob

http://gis.stackexchange.com/questions/108641/qgis-raster-calculator-need-values-to-be-set-to-0-instead-of-no-data
http://gis.stackexchange.com/questions/110248/saga-raster-calculator-ifelse-command-syntax-problem
http://gis.stackexchange.com/questions/42555/what-to-do-with-3-4e38-nodata-values
http://gis.stackexchange.com/questions/81640/how-to-set-all-pixels-with-value-0-to-nodata-in-dem-raster 
(hoping to reverse engineer this process)
http://gis.stackexchange.com/questions/22786/how-to-exclude-missing-values-from-raster-layer

Hi,
I am not a raster math genius but I will give this a shot.

1)". In this case all cells outside the extent of rasterB get assigned 
"nodata" which is the default -3.4028234663852886e+38 in my case. Is 
that correct?

-Yes that is a standard null data for float 16 or float 32 files.  It 
can be change with gdal-warp or gdal-translate. I suspect that is you 
save the file in ASCII grid format, you will have no more null values... 
And less hard drive space!

-If you multiply a value by a null value, you will get a null value in 
the answer.  That explains what is going on in point 1 and 2.

As for point 4, you can probably do it with a mask. Something like 
rasterA/rasterA should give you a mask with 1 where there is data and 
zero when not (I think. If not reset with gdal-translate).  Then you can 
use the AND function to combine areas and find where raster A and B 
intersect and work your way from there.  You could also find the extent 
of the rasters (in vectors) and then use the vectors to raster operation 
to create a mask.

Stuff I found:
http://gis.stackexchange.com/questions/22786/how-to-exclude-missing-values-from-raster-layer

http://gis.stackexchange.com/questions/12418/how-to-redefine-the-nodata-value-into-zero-in-qgis

http://gis-lab.info/qa/rastercalc-eng.html#How_does_it_work

http://gis.stackexchange.com/questions/33764/how-to-change-null-values-raster-values-to-0-in-qgis

http://docs.qgis.org/2.6/en/docs/training_manual/rasters/terrain_analysis.html#moderate-fa-using-the-raster-calculator

http://docs.qgis.org/2.2/en/docs/training_manual/processing/no_data.html

Good luck

Nicolas Cadieux M.Sc.
Les Entreprises Archéotec inc.
8548, rue Saint-Denis Montréal H2P 2H2
Téléphone: 514.381.5112  Fax: 514.381.4995
www.archeotec.ca

Le 2015-02-24 12:26, "Michael.Scholz [via OSGeo.org] " <[hidden email] 
<http://osdir.com/user/SendEmail.jtp?type=node&node=5189844&i=0>> a écrit :
Hey!
In QGIS 2.6.1 I spent the whole day on the raster calculator for some 
super-simple overlay calculations and I'm ending up in rage and fury. I 
don't want to complain about the unintuitive syntax. Rather I have some 
questions:
1) I have two raster with different extents. rasterA entirely contains 
rasterB. When I add these rasters (rasterA + rasterB) and set the output 
extent to the same as of rasterA, my result is only defined at the 
overlapping area of both rasters. In this case all cells outside the 
extent of rasterB get assigned "nodata" which is the default 
-3.4028234663852886e+38 in my case. Is that correct?
2) I extended rasterB to have the same extent as rasterA by filling the 
missing cells with "nodata". rasterA + rasterB still gives the same 
result as in 1). Why is "rasterA + nodata = nodata"? I just want values 
from rasterB to be added to values of rasterA AND keeping rasterA 
entirely where rasterB has no values.
3) How can I query the "nodata" value of a band?? Without being able to 
query it, I cannot set it to 0 which would solve all my problems.
4) I would like to express something like "(rasterB = nodata AND rasterA 
!= nodata) * rasterA + (rasterB != nodata) * (rasterA + rasterB)". Is 
that possible?

Still in love with QGIS
Michi Scholz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20150225/b263588a/attachment.html>


More information about the Qgis-user mailing list