1

using QGIS 2.18.1 in Windows 10, what I have is 2 raster files with different cell sizes. raster1 has small cell sizes, and represents land uses (each cell value represent a land Use) and raster2 has bigger cell sizes and represents precipitation values. You can see it from the image:

enter image description here

I need to assign to each cell in raster1, the value of the overlapping cell value of raster2. And in the cases in which a cell in raster1 overlaps with 2 cells in raster2 (A cell between 2 cells of raster2), get the value of the raster2 cell overlapping bigger surface.

I could do this by polygonizing both raters and applying python code to get most predominant values within polygons (like in this question) but I wonder if there's an easier way to do this by using the raster calculator or other raster tools.

0

Sure, you have the right idea. Load both raster datasets into QGIS, and open the Raster Calculator. They should both be visible in the upper left hand of the window, under "Raster bands". Select (but don't double click) the layer raster1, and to the right click "Current layer extent". The numbers for Columns and Rows should populate - these correspond to the resolution, or the number of cells within the defined spatial extent. To be sure, go into the layer properties for raster1 beforehand and make sure these match up.

Then, double click on raster2 in the "Raster bands" panel. This is your "Raster calculator expression" - meaning that for each defined cell in the spatial extent, the value will be taken from the second raster, as you have defined it. Name your output layer (click "..." to save to file, as whatever type you choose), and click okay.

The process defaults to a nearest neighbor, so you should have no issues with the definition of cells on the border. If you notice irregularities, another alternative is to process this in the Python Plugin window using a gdal_calc command, but this should give you the desired output.

  • Thanks, it indeed works but actually what I get is the same raster2, with the number of columns and rows of raster1. But it's ok, What I can do now is to clip the resulting raster with the raster1 polygonized, and then I get what I need. Thanks a lot! – Alex Fernández Poulussen Feb 1 '18 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.