What I am trying to do is looping trough the active vector layers features and create for each polygon a rasterfile.

My approach is using gdal:rasterize in every iteration, but it wont work at the moment.

from qgis.core import *
from qgis import processing
import qgis.utils
from qgis.core import QgsVectorLayer
import os

outfolder = r'/home/user/Schreibtisch/raster'

activeLayer = qgis.utils.iface.activeLayer()
activeLayerFeatures = activeLayer.getFeatures()

for e, polygonFeature in enumerate(activeLayerFeatures):
    outname = 'Polygon_{}.tif'.format(e)

        {'INPUT':QgsProcessingFeatureSourceDefinition(activeLayer.id(), True),

First of all, is this the right approach? Or will this never work?

Anyway, when I run this script, I get the error

ERROR 1: Attempt to create 0x0 dataset is illegal,sizes must be larger than zero.

I tried playing around with the extend, which I copied out of the vectorlayers metadata, and the resolution, but it wont work.

  • That error means that, based on the inputs you have provided (units, width, height and extent) you are telling gdal to write a raster which is less than a single pixel in size. So there is something wrong with those parameters. What CRS is your polygon vector in?
    – Ben W
    Jul 1, 2021 at 3:12


Your Answer

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