I recently posted an answer to Zonal stats for complete pixels qgis that required clipping a raster in a way that excludes pixels that fall partially outside the mask layer. Here's an illustration:
The best method I could figure out is as follows:
- Polygonize the raster.
- Use Select by location tool to select features in Vectorized layer
that fall within the polygon layer. - Clip raster by mask layer using the selected features of the
Vectorized layer as the mask layer. Don't crop the extent.
But this method seems like a lot of steps, and polygonizing a large raster can take a long time.
Is there a better method of clipping a raster and excluding cells that overlap the edge of the mask?
By "better" I mean fewer steps and/or requiring less processing time.
Best Answer
I'm not aware of a better way to do this using QGIS. I wrote the
exactextractr
package for R out of a need to solve problems like this, where the nature of polygon/raster cell intersections is important. It is much, much faster than creating a polygon for each cell and doing an intersection calculation. If you can use R, maybe it will be of use to you. Here is an example:This produces the following output: