Experimental
Calculates or updates a field value from SQL-style or expression-style formulas using feature attributes and geometry variables.
vector attributes expression
| Name | Description | Required | Default |
|---|---|---|---|
input | Input vector layer. | Required | input.shp |
field | Output field name. | Required | score |
field_type | Output field type: float, integer, text. | Optional | float |
expression | Expression or SQL-style UPDATE assignment evaluated per feature. | Required | VALUE * 2.0 + $area |
overwrite | Overwrite existing field if present (default true). | Optional | True |
preview_rows | Optional number of preview rows to return in payload. | Optional | 0 |
output | Output vector path. Optional when preview_rows > 0. | Optional | — |
Computes a derived numeric field using attributes and geometry.
wbe.field_calculator(expression='VALUE * 2.0 + $area', field='score', field_type='float', input='input.shp', output='field_calc.shp', overwrite=True)
SQL-style conditional update using CASE and UPDATE wrapper.
wbe.field_calculator(input='roads.gpkg', field='SPEED', field_type='integer', expression="UPDATE roads SET SPEED = CASE WHEN TYPE == 'motorway' THEN 100 WHEN TYPE == 'primary' THEN 80 ELSE 60 END", overwrite=True, output='roads_speed.gpkg')
Preview-only evaluation for first 10 rows (no output write).
wbe.field_calculator(input='roads.gpkg', field='SPEED', field_type='integer', expression="CASE TYPE WHEN 'motorway' THEN 100 ELSE 60 END", overwrite=True, preview_rows=10)