1

I'm having trouble finishing the QGIS tutorial for Using Custom Python Expression Functions: http://www.qgistutorials.com/de/docs/custom_python_functions.html

I get to the point where I write the script in the function editor, but when I want to use the function in an expression it looks different and doesn't work.

Screenshot 1 is what it looks like in the tutorial, screenshot 2 is my result when I double click on the custom function. The code is the same, I copy pasted it into the functions editor. When I write the exact same expression as in the tutorial it says 'expression invalid' (screenshot 3).

enter image description here enter image description here enter image description here enter image description here enter image description here enter image description here

6
  • Have you tried using this expression: GetUtmZone('40N') Sep 13, 2016 at 11:37
  • Yes I did, but it also says 'invalid expression' (see screenshot 4) Sep 13, 2016 at 11:38
  • Did you register the function after writing it by clicking Run Script button?
    – artwork21
    Sep 13, 2016 at 12:19
  • Well, the thing is, I don't have a Run Script button like the one in the tutorial. I posted another screenshot of what my function editor looks like. I only have a "Load" button. I clicked that one, it made the function appear under "Custom" in the expression part. Sep 13, 2016 at 12:32
  • Click on More Info it will tell you what is wrong.
    – Nathan W
    Sep 13, 2016 at 12:40

1 Answer 1

9

Try this if you want to Select by Expression

GetUtmZone() = '40N'

If you just need to get the return value from the function you can just do

GetUtmZone()

The $ prefix used to be used for functions that took no arguments however that is no longer used in later versions, the version in the tutorial is a older QGIS version that still supported that format.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.