I am trying to use gdal utilities like gdal_polygonize in python to polygonize my raster image but I'm having trouble understanding the commands. What I mean is in some places the command is of the given form say:
gdal.Polygonize( srcband, None, dst_layer, -1, [], callback=None )
I found it here
And the command is also called in python with os.system().
I read and tried to implement commands from Gdal_polygonize: How to filter pixels above a given value (elevation)?
gdal_polygonize.py result.tif result.shp
and python gdal_polygonize error
os.system('gdal_polygonize.py ' + filename + ' -f "ESRI Shapefile" ' + shapefile)
but no shapefile is created although there was no error while running the code.
I am stuck and having great trouble learning to use gdal with python as I don't understand the need or difference between the two types of commands. Please address my question.
What is the proper syntax for using (lets say) gdal_calc.py when called with os.system() and also when used as gdal_calc() ?
P.s I use python 2.7 on win 8.1 platform.
EDIT: With gdal.polygonize() I get the output shapefile, but when I try to view it in qgis, I get nothing but white screen. And in the case where I try to call utilities with os.system(), I don't get an output file only. Please tell me what is going wrong.
os.system
is deprecated, use the standard module subprocess. For a pure Python solution, look at Python GDAL/OGR Cookbook: Polygonize a Raster Band