Field Calculator
field_calculatorAdds a missing field or populates an existing one from a QGIS expression per feature in place, returning updated and failed counts.
Instructions
Add (if missing) + populate a field from a QGIS expression, per feature, in-place. field_type: string|int|double|bool|date|datetime (default double). Example: expression='$area', field_name='area'. $area/$length use the project's ellipsoid and units (reported back as 'measurement'), not necessarily m2/m; the area()/length() functions are planimetric in the layer CRS (measurement.planimetric_units, squared for area()); length() of a string counts characters and reports no units. Returns updated and failed counts; failed features keep their old value and first_error says why. Refused while the layer has an open edit session.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"layer_id": "<layer_id>",
"field_name": "<field_name>",
"expression": "<expression>"
},
"name": "field_calculator"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| length | No | ||
| layer_id | Yes | ||
| precision | No | ||
| expression | Yes | ||
| field_name | Yes | ||
| field_type | No | double |