Using FieldPyculator for QGIS

Python power for your calculations

It’s available in the QGIS plugin repository and thus installable with ‘Fetch Plugins’; source available on github. According to their webpage, FieldPyculator was developed by GIS-Lab. They have a Russian-language introduction to the plugin on their webpage, with an excellent Google translation.

Using

Use the toolbar button or the Plugins|FieldPyculator menu to open the dialog.

  • Enter your Python code in the “Field expression” text box. Values are assigned by the value = statement – this must exist in some form in the final code.
  • If you need other libraries, or to set up variables or any other code that runs once before the field expression, tick the ‘Global expression’ button and enter the code in that text box.
    • For example, to use the datetime functions, you would enter import datetime as the Global Expression and could then use a command like value = datetime.date.today() as the Field Expression.
    • You could also set a variable in the Global Expression (such as f = 123.45‘) and use that in calculations.

Notes

  1. There doesn’t seem to be a way to create a new field in the dialog, unlike the usual field calculator. You have to add a new column somewhere else and then use it here.
  2. I can’t seem to get ‘IF’ statements working …