0

I have two overlapping raster dataset with the same resolution. First one is classified into 1 and 0 values. I would like to clip the second raster based on the pixels of the fist raster with value equal to 1.

Is there any tool that can do this job in QGIS?

  • Try Clip Raster by Mask Layer from menu Raster > Extraction. – Kazuhito Aug 31 at 22:41
  • 1
    @Kazuhito The extraction tool requires a vector layer, so the first step will be to convert the raster to vector and then use appropriate vector features for the clipping. – spatialthoughts Sep 1 at 10:50
3

You can clip a raster by a vector easily, so first step is to convert your raster to vector.

  1. GDAL > Raster Conversion > Polygonize.
  2. You will have polygons with attribute called DN with values 0 and 1. Select all polygons with value 1 with expression like DN = 1
  3. Use GDAL > Raster Extraction > Clip raster by mask layer. Select the polygonized layer as the mask layer and check the 'selected features only'
  • Thank you @spatialthoughts. It worked perfectly. – Sher Sep 3 at 9:16
1

You can also use raster calculator for this:

  1. Select 'Raster' > 'Raster Calculator...' use the expression ("Mask_raster@1"=1)*"Raster1@1" + ("Mask_raster@1"=0)*-9999 (replace Mask_raster and Raster1 with your layer names).
  2. Select 'Raster' > 'Conversion' > 'Translate (Convert Format)...'. Set the input layer as the layer you just created in raster calculator and assign the nodata value as -9999.

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.