When I run the script below, I got this error:

enter image description here

rps=10000 #RasterPixelSize

layer = iface.activeLayer()
extent = layer.extent()
xmin = extent.xMinimum()
xmax = extent.xMaximum()
ymin = extent.yMinimum()
ymax = extent.yMaximum()

param = {"INPUT": layer,
         "FIELD": "PolygonId",
         "BURN": 0,
         "UNITS": 0,
         "WIDTH": rps,
         "HEIGHT": rps,
         "EXTENT": "%f,%f,%f,%f" % (xmin, xmax, ymin, ymax),
         "NODATA": 0,
         "OPTIONS": None,
         "DATA_TYPE": 5,
         "INIT": 0,
         "INVERT": False,

processing.runAndLoadResults("gdal:rasterize", param)
  • 1
    What is "sdx"? Did you try using a full path (e.g. "OUTPUT": "path/to/sdx.tif")? – Joseph Jan 29 '18 at 15:06
  • Yes yes I tried them all: " ", "D:/raster.tif", "raster" – Mustafa Uçar Jan 29 '18 at 21:17
  • If your run the algorithm through the toolbox with the same parameters, does it work correctly? – ndawson Jan 29 '18 at 22:06
  • Yes. When I run it from toolbox it works – Mustafa Uçar Jan 30 '18 at 6:38

I solved the problem:

    param = {'BURN': 0.0,
             'DATA_TYPE': 5,
             'EXTENT': "%f,%f,%f,%f" % (xmin, xmax, ymin, ymax),
             'FIELD': 'PolygonId',
             'HEIGHT': rps,
             'INIT': 0.0,
             'INPUT': fileName,
             'INVERT': False,
             'NODATA': 0.0,
             'OPTIONS': '',
             'OUTPUT': QgsProcessingOutputLayerDefinition(dosya),
             'UNITS': 0,
             'WIDTH': rps}

fileName should be path of the vector file.

QgsProcessingOutputLayerDefinition(dosya) should be path of the raster layer with *.tif extension

That's all!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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