I want to create a very simple script in python that polygonizes a raster. Based on python cookbook + forums search I wrote the following code
#import des modules
from osgeo import gdal, ogr
from qgis.core import *
from qgis.gui import *
import sys
from PyQt4.QtCore import *
##srcRaster=Raster
##Result=output vector
# 1. Open Raster and get band 1
src_ds = gdal.Open(srcRaster)
srcband = src_ds.GetRasterBand(1)
# 2. Create output datasource
Result = QgsVectorLayer("Polygon", "temporary_points", "memory")
Result.startEditing()
Result.dataProvider().addAttributes([QgsField("ClassNo", QVariant.String)])
Result.updateFields()
gdal.Polygonize( srcband, None, Result, 0, [], callback=None )
which ends up with the error "in method 'Polygonize', argument 3 of type 'OGRLayerShadow *". The truth is, I don't really understand what should be the syntax of gdal_polygonize in a qgis python script (command line can be found here).
Could anybody please help ?
No comments:
Post a Comment