I'm trying to make a little tool who do a concave hull, and calculate its surface in a new field. I'm not a python pro, so I began with treatment modeler like this : enter image description here

It works very well ! But I have to treat more than hundred shapes, so I decide to save my model in python script and edit it to treat all shapes in a folder. In first time, I wanted to try python script I saved. But strangely, it doesn't work... I have a weird message... enter image description here

Here is my code :

##Calcule de surface cultivee=name
##couchedesortie=output vector

outputs_QGISCONCAVEHULL_1=processing.runalg('qgis:concavehull', couchedepiedsdevigne,0.3,False,False,None)
outputs_QGISFIELDCALCULATOR_1=processing.runalg('qgis:advancedpythonfieldcalculator', outputs_QGISCONCAVEHULL_1['OUTPUT'],"SURFACE",1,10.0,3.0,True,'$area',couchedesortie)

I don't understand why it's working in treatment modeler and not in python script... Somebody can help me ?

  • which exact version of 2.18? Did you install from Development or Latest Release? Looks similar to this issue
    – Steven Kay
    Jul 18, 2017 at 19:54
  • I have QGIS 2.18.9
    – Tim C.
    Jul 20, 2017 at 12:17

1 Answer 1


You may be missing some dependecy imports and if you do not want to batch select hundreds of files you may use os.walk() to iterate through directory of many directories:

import processing, os

for root, dirs, files in os.walk('C:/someRoot/shp/dir'):
  for file in files:
    if file.endswith('.shp'):
      shpFile = root + '//' + file
      outputs_QGISCONCAVEHULL_1 = processing.runalg('qgis:concavehull', shpFile,0.3,False,False,None)
      outputs_QGISFIELDCALCULATOR_1 = processing.runalg('qgis:advancedpythonfieldcalculator', outputs_QGISCONCAVEHULL_1['OUTPUT'],"SURFACE",1,10.0,3.0,True,'$area',couchedesortie)

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.