[GIS] How to use field calculator from QGIS Sextante plugin

field-calculatorqgissextante-qgis-plugin

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
end

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

Best Answer

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)

Formula

value = f( <PointConfL> )