Wednesday 23 January 2019

Performing addition in QGIS Raster Calculator?


I am using QGIS 2.6 on Windows 7.


I have generated two rasters from vector layers. They cover the same extent and have the same projection (Irish Transverse Mercator) and cell size (5m x 5m). I have 'reclassified grid values' to ensure that both rasters now have values of only 0 or 10. I have been attempting to add the rasters together in the raster calculator ("NPWS@1"+"CH_Extract@1") and I am expecting to see values of 0, 10 or 20 (where there is overlap between the two original vector datasets). Instead I get an output layer with values of 0 or 9.989990. I have tried every permutation I can think of to fix this and am having no joy.



Answer



The problem is that your individual rasters are not aligned. So, when they are added the result is a weighted average for the values in the overlaping area. To solve this you have to use a merged vector layer whose extension must be used for producing individual raster. I used this procedure for testing it:


1) I created two vector layers (both with the same value field = 10) where they are overlaped in some area:


enter image description here


2) I merged them and I wrote down its extension:



enter image description here


3) Using the extension to rasterize (by value field = 10) the first vector layer:


enter image description here


4) First vector layer rasterized:


enter image description here


5) Second vector layer rasterized:


enter image description here


6) sum_raster obtained by using raster calculator. You can observe that the sum is 20 in overlaped areas (Value Tool plugin). The values: 0 (black area), 10 (gray area), 20 (white area).


enter image description here


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...