1

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

5
  • 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
    Commented 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
    Commented 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
    Commented 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
    Commented Dec 30, 2021 at 14:10
  • but the error of code has realtion with vector or raster?
    – resuk
    Commented Dec 30, 2021 at 14:59

3 Answers 3

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

7
  • 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
    Commented Dec 30, 2021 at 12:36
  • @resuk your comment is not clear Commented 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
    Commented 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
    Commented 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
    Commented Jan 3, 2022 at 14:40
0

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

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

The process described in this question might help you too. The key point is after Raster -> Extraction -> Clip raster by mask layer, you need to click on the little circulation sign:

enter image description here

Bigger picture:

enter image description here

Output: separate raster layers.

enter image description here

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.