[Qgis-user] QGIS Raster Calculator - cannot add two mutually exclusive areas with logical statement because nodata excludes the other's data

Nicolas Cadieux nicolas.cadieux at archeotec.ca
Wed Jun 3 05:47:51 PDT 2015


Hi, 
If the no data value is a problem, you can change it.  Look at this post.  If you are more comfortable with the GRASS and SAGA raster calculators, you can access them using the "processing plugin". 
http://gis.stackexchange.com/questions/81640/how-to-set-all-pixels-with-value-0-to-nodata-in-dem-raster 
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 
On Jun 1, 2015 6:09 PM, "robertlozar [via OSGeo.org]" <ml-node+s1560n5208547h18 at n6.nabble.com> wrote: 

	I cannot figure out how to overcome the QGIS raster calculators rules.  
I need to calculate the Leaf Area Index -LAI- from satellite image bands. The LAI is dependent on the Land Cover -LC - 
Type.  For each LC, I need to result in 3 mutually exclusive conditions: 
LAI > 0, then calculate the value
LAI < 0, set the value to zero (or a vanishingly small positive number)
Not current LandCover, set the value to nodata.
Then each different LC will be exclusive of all others.  So I will have to add many mutually exclusive areas together.
I have written the equations as above for each of the landcover types separately.  All I have to do is add one to the 
next to get a map of LAI for the three conditions and then for all the landcovers. 
The problem is the QGIS Raster Calculator will not let me do the simple addition.  It seems the reason is the nodata 
from the landcover type is what QGIS Raster Calculator is what takes priority over the data in the addition and all I 
get is a final map full of nodata.  I cannot find a way of overcoming this "feature".  I cannot believe such a simple 
action is not possible in any GIS.  Can someone point out where I am going wrong?  
Thanks, Bob
Note-I have done this in GRASS and ArcGis and Iknow it can be done in SAGA and the the QGIS plugings. Since the .tif 
format is the standard for QGIS, one should not have to put the images into ascii format as some have suggested or use 
gdal_translate to get zeros and nodata separated (which does not work anyhow). I am asking specifically about the QGIS 
Raster Calculator because I cannot believe it is not possible.
The actual equations I have been using look like this:
case 1 - calculates LAI for LC code 41 above zero correctly:  
(("nlcd_2011_benning_areawgs84z16.tif@1"  = 41 ) AND (("nlcd_2011_benning_areawgs84z16.tif@1"  = 41 ) * ( 2.8 -102 * 
"clip_RT_LC80190382014318LGN00_B04@1"  + 28 
* "clip_RT_LC80190382014318LGN00_B05@1" - 41 * 
"clip_RT_LC80190382014318LGN00_B06@1" )     >=    0)) * ( 2.8 -102 * "clip_RT_LC80190382014318LGN00_B04@1"  + 28 * 
"clip_RT_LC80190382014318LGN00_B05@1" - 41 * 
"clip_RT_LC80190382014318LGN00_B06@1" )
case 2 - calculates LAI for code 41 below zero to a small value correctly:  
(("nlcd_2011_benning_areawgs84z16.tif@1"  = 41 ) AND (("nlcd_2011_benning_areawgs84z16.tif@1"  = 41 ) * ( 2.8 -102 * 
"clip_RT_LC80190382014318LGN00_B04@1"  + 28 
* "clip_RT_LC80190382014318LGN00_B05@1" - 41 * 
"clip_RT_LC80190382014318LGN00_B06@1" )     <=    0)) * .0000001
case 3 - set value for all codes NOT 41 to a vanishingly small number:
(("nlcd_2011_benning_areawgs84z16.tif@1"  != 41 ) * .0000002)
So the final equation for Code 41 should be (but is NOT) as follows because 
    1. qgis does not allow you to add one layer to a second that is in the seconds nodata area [same for + AND and OR 
between each] and 
    2. ("your_raster" != -32768) * "your_raster" does not work because image data is UInt16 in which nodata value 
cannot be addressed (this statement may work for other formats)
The equation for Code 41
(( (("nlcd_2011_benning_areawgs84z16.tif@1"  = 41 ) AND (("nlcd_2011_benning_areawgs84z16.tif@1"  = 41 ) * ( 2.8 -102 * 
"clip_RT_LC80190382014318LGN00_B04@1"  
+ 28 * "clip_RT_LC80190382014318LGN00_B05@1" - 41 * 
"clip_RT_LC80190382014318LGN00_B06@1" )     >=    0)) * ( 2.8 -102 * "clip_RT_LC80190382014318LGN00_B04@1"  + 28 * 
"clip_RT_LC80190382014318LGN00_B05@1" - 
41 * 
"clip_RT_LC80190382014318LGN00_B06@1" ) )  OR ((("nlcd_2011_benning_areawgs84z16.tif@1"  = 41 ) AND 
(("nlcd_2011_benning_areawgs84z16.tif@1"  = 41 ) * ( 2.8 -102 * "clip_RT_LC80190382014318LGN00_B04@1"  
+ 28 
* "clip_RT_LC80190382014318LGN00_B05@1" - 41 * 
"clip_RT_LC80190382014318LGN00_B06@1" )     <=    0)) * .0000001  ) OR   (("nlcd_2011_benning_areawgs84z16.tif@1"  != 
41 ) *  (.0000002 )  ) )

	
	
	
	
	
	
	
		If you reply to this email, your message will be added to the discussion below: 
		http://osgeo-org.1560.x6.nabble.com/QGIS-Raster-Calculator-cannot-add-two-mutually-exclusive-areas-with-logical-statement-because-nodataa-tp5208547.html 
	
	
		To start a new topic under Quantum GIS - User, email ml-node+s1560n4125267h38@n6.nabble.com 
		To unsubscribe from Quantum GIS - User, click here . 
		NAML 
	



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/QGIS-Raster-Calculator-cannot-add-two-mutually-exclusive-areas-with-logical-statement-because-nodataa-tp5208547p5208898.html
Sent from the Quantum GIS - User mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20150603/196c2511/attachment.html>


More information about the Qgis-user mailing list