I am trying to use the Sextante field calculator to calculate a field for a buffer radius using a categorical text field. The formula works fine when I run it using the standard QGIS field calculator via the attribute table:

QGIS field calculator

When I use the same formula from the Sextante toolbox however (algorithms for vector layers), it produces only null values.

enter image description here enter image description here

This is the formula I'm using:

case when  "PointConfL"  =  '10-50 km' then 50000 
when  "PointConfL"  =  '5-10 km' then 10000 
when  "PointConfL"  =  '2-5 km' then 5000 
when  "PointConfL" =  'centroid of farm' then 10000 
else 50000

It seems to not matter whether the new field exists before or not: if it doesn't exist, it is created, but in both cases, all values are NULL.

Am I using the 'algorithm' incorrectly, or is this perhaps a bug in the plugin?

EDIT: I found the error log in ~/sextante, but it doesn't shed much light on the problem:

ALGORITHM|Wed Oct 24 2012 17:08:08|Sextante.runalg("sextante:fieldcalculator","/home/rudi/personal/GIS/projects/transform_count/364-236.shp","buffer_sextante","case when  "PointConfL"  =  '10-50 km' then 50000 when  "PointConfL"  =  '5-10 km' then 10000 when  "PointConfL"  =  '2-5 km' then 5000 when  "PointConfL" =  'centroid of farm' then 10000 else 50000 end")
ERROR|Wed Oct 24 2012 17:08:08|Problem evaluation formula: Wrong field values or formula
  • 1
    Looking at the error log, I thought it might be a result of mixed string delimiters (" and '), but I tried changing them all to ' and it still had the same result Oct 24, 2012 at 19:08
  • On simple tests (e.g. bufQGIS * 2), the field calculator works, but all apostrophes should be removed from field names. I have not managed to get even a simple case statement to work yet. Oct 24, 2012 at 19:45
  • After looking at the code, it seems that Sextante implements its own version of the field calculator, and can only handle arithmetic operations. Case statements are simply not possible with the current implementation of Sextante's field calculator. Oct 27, 2012 at 10:55

1 Answer 1


For advanced field manipulation, you should rather use the Field Pyculator, which is currently only available in the development version of the plugin. The desired results would be achieved by using the following parameters:

Global expression:

def f(x): return {'10-50 km':50000,'5-10 km':10000,'2-5 km':5000,'centroid of farm':10000,}.get(x,50000)


value = f( <PointConfL> )

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.