Geographic Information Systems Asked on January 18, 2021
Given two input layers
I want to create an output raster whose overall extent matches the extent of the mask layer and each pixel is either NO DATA if the corresponding pixel of the mask layer is NO DATA or the value of the corresponding pixel from the clip layer if the corresponding pixel of the mask layer is not NO DATA.
I know I can mask the clip layer with a polygon, but the mask layer is a raster. Polygonizing the raster layer is possible in principle, but would result in a polygon with a lot of very short edges.
Is there a direct way to do this in QGIS?
I suppose there’s probably a path that involves creating a new layer and using the raster calculator, but I’m hoping there’s something more direct. Further complicating the matter is that the two rasters might not have the same resolution and origin.
I believe this is equivalent to Extract by Mask in ArcMap.
The simple way to do this in QGIS is to use the Raster Calculator (Raster->Raster Calculator
). You have a couple of options. The easiest to explain/understand is to make a unitary raster from your mask (all data set to either 1 or NoData) and then multiply your clip layer by the unitary mask layer.
To ensure the extents match the mask layer, in the raster calculator window select the mask layer in the 'Raster bands' list on the left and then click the 'Current layer extent' button on the right.
You can create a unitary mask on the fly by using a conditional statement (see the link) something like this:
(maskLayer@1 >= 0) * clipLayer@1
This statement basically says: treat everything in my mask layer that is not NoData as being equal to 1 (NoData stays as NoData). Just be sure to remember to set the extent (see above)!
Raster Calculator and paletted data:
Any output from the raster calculator will be just values and not carry over any information contained within a colour pallet. You have a couple of options to 'get your palette back':
Correct answer by MappaGnosis on January 18, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP