2

i'm trying to execute gdal_polygoinize.py command. I have a main python method that takes in input a raster file and a output shapefile, and then calls a method named polygonize.py that builds and try to execute the gdal_polygonize command.

The code is:

format = "ESRI Shapefile"
command_poligonize = "gdal_polygonize.bat " + \
                        + input_raster + ' '\
                         '-f ' + '"' + format + '"'+ \
                         shape_output
status=subprocess.call(command_poligonize, shell=True)

i tryed also with the os.system() method:

os.system(command_poligonize)

Executing the command:

print('DEBUG: comand: ' + command_poligonize)

i obtain the correct gdal_polygonize invocation, like:

gdal_polygonize.py input.tif -f "ESRI Shapefile" output.shp

The error description is the following:

  File "C:\OSGeo4W64\bin\gdal_polygonize.py", line 209, in <module> 
     callback = prog_func )
 File "C:\Python35\lib\site-packages\osgeo\gdal.py", line 1636, in Polygonize
     return _gdal.Polygonize(*args, **kwargs)
 RuntimeError: Object given is not a Python function

Any suggestion?

I tryed to run the command by itself, like:

gdal_polygonize.py input.tif -f "ESRI Shapefile" output.shp

and it return with the following error:

  File "C:\OSGeo4W64\bin\gdal_polygonize.py", line 209, in <module> 
     callback = prog_func )
 File "C:\Python35\lib\site-packages\osgeo\gdal.py", line 1636, in Polygonize
     return _gdal.Polygonize(*args, **kwargs)
 RuntimeError: Object given is not a Python function

I'm using Python35 and Gdal 2.0.2 released 2016/01/26.

4
  • Does it work when you run the command by itself? It appears you are in a Windows environment (I see gdal_polygonize.bat); are you running this Python code from the same environment as the GDAL environment? Commented May 25, 2016 at 12:07
  • @EvilGenius same question as Evil. I still see .bat in your updated post. gdal_polygonize.bat input.tif -f "ESRI Shapefile" output.shp Commented May 26, 2016 at 16:12
  • just run gdal_polygonize.py input.tif -f "ESRI Shapefile" output.shp or gdal_polygonize input.tif -f "ESRI Shapefile" output.shp and specify the input and output location Commented May 26, 2016 at 16:13
  • The command is: gdal_polygonize.py. located into C:\Python35\Lib\site-packages\osgeo\scripts. The commands gdal_polygonize.py input.tif -f "ESRI Shapefile" output.shp or gdal_polygonize input.tif -f "ESRI Shapefile" output.shp exit both with the same error described in the question, also specifying the input.tif and output.shp with the complete path.
    – lorenzo
    Commented May 26, 2016 at 16:26

3 Answers 3

3

Running gdal_polygonize.py on Windows, the problem does seem to be with the callback function (used to show progress in the terminal).

A workaround is to set the -quiet or -q flag, e.g.:

gdal_polygonize.py -q input.tif -f "ESRI Shapefile" output.shp

2

I had this same problem, the issue is the callback parameter being sent to gdal.Polygonize, if you go into he script and remove it from line 208 it should fix your issue.

0
0

I report the respective Qgis code:

gdal_polygonize.bat E:\Sviluppo\features_extraction\test\AIRONE_FPL_NoFlyZone_16bit.tif -f "ESRI Shapefile" E:/Sviluppo/features_extraction/test/output_v2.shp output_v2

it works succesfully.

the gdal_polygonize.bat code is:

@python "%OSGEO4W_ROOT%\bin\gdal_polygonize.py" %*  

It may be that i miss some parameters?

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.