I have two layers. The first one is a vector layer with a lot of polygons. The other one is a raster layer. I need to extract raster to many rasters by individual polygons of the vector layer.

I tried the option Raster > Extraction > Clip Raster by mask layer but just one raster was extracted and not of each polygon.

This is my code and the error:

enter image description here

enter image description here

  • Strange, should work.. What if you rename the raster layer in the layer list/tree to something else and adjust line two. Like raster1. And/or restart qgis and try again. Your raster isnt a WMS layer or some other remote service right?
    – BERA
    Dec 30, 2021 at 12:04
  • i changed name by raster1.tif but they show me the same error, my raster is a an imager GeoTIFF
    – resuk
    Dec 30, 2021 at 12:08
  • which model exactely? using each polygone isn"t possible i have i lot of should i use one layer composed by many polygons to split raster
    – resuk
    Dec 30, 2021 at 12:16
  • Are they all singlepart polygons with good geometry? It looks like you have a lot of polygons of potentially "interesting" shapes which might favor using selections to do the clips and then merging them together.
    – John
    Dec 30, 2021 at 14:10
  • but the error of code has realtion with vector or raster?
    – resuk
    Dec 30, 2021 at 14:59

2 Answers 2


You can build a model with Vector Features input. It will then iterate over each polygon and clip the raster. Make sure to tick "Iterate over this layer..." when you execute the model:

enter image description here

enter image description here

  • This model seems that will be give the same results like extract by mask plugin, i mean will consider vectoe with many polygone like just one to split imagery
    – resuk
    Dec 30, 2021 at 12:36
  • @resuk your comment is not clear Jan 3, 2022 at 14:14
  • It will give one raster per polygon. If not you are using Vector Layer as input, and not Vector Features. Or havent ticked the iterate... box
    – BERA
    Jan 3, 2022 at 14:17
  • yes it works good with the plugin split raster by mask also, i am interessted to code juste to give to each raster of the severals rasters the name of id polygone using to split it, i wich u understand me
    – resuk
    Jan 3, 2022 at 14:31
  • Ok I understand. I dont think that is possible using a model, you need pyqgis. Another option is to rename all temp outputs after the model using pyqgis.
    – BERA
    Jan 3, 2022 at 14:40

Perhaps your polygon layer has geometry errors. Run the Fix Geometry tool, which is found in the Processing Toolbox.

  • i fixed geometry but the same error
    – resuk
    Dec 30, 2021 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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