10

I'm using Essen and trying to follow Anita Graser's wonderful tutorial Illuminated contours. I've created the azimuth function and loaded it but there is nothing showing in the expression tab - not even Custom with the default func! The expression exists as azimuth.py in C:\Users\Max\.qgis2\python\expressions with associated .pyc file. Restarting QGIS doesn't make any difference

enter image description here

enter image description here

  • 2
    I take it you remembered to hit the 'Load' button? I also found some older scripts caused problems when I tried to reallocate them to a new group - I got no syntax errors, but correcting indentation manually from using TAB to 4 spaces fixed this. This might be worth checking, especially if you pasted the code in? (I see you're using 2 spaces for indent). The fold marker (the minus sign after the line number) looks ok though... – Steven Kay Oct 24 '16 at 19:34
  • @StevenKay Thanks Steven for the first time I have an error on the code and it is to do with indentation. I wasn't aware of this and yes I had pasted the code in.. Just to confirm, there should always be 4 spaces at the beginning of a line - I notice that the function editor does some automatic indentation? – Max Oct 25 '16 at 10:16
  • @Max - I would strongly suggest using a text editor to fix your indentation and then paste it into the expression window. A number of these editors will highlight whether your indentation is wrong. There are many text editors out there, for example, I love using Sublime ;) – Joseph Oct 25 '16 at 11:23
  • 1
    @Joseph Thanks I will do - really appreciate all the assistance – Max Oct 25 '16 at 11:31
  • @Max Did you ever solve this? I experience the same. My custom functions do not load when qgis starts so I have to enter the function editor tab and press "load" before the custom functions show up in the expression editor tab. – joskal Mar 7 '18 at 7:57
11

Do not call the function azimuth as there is already an existing Math function called this.

Instead give it another name like azi():

Example script

And now you should be able to call it:

Custom expression

  • thanks for that, I wasn't aware of the math function. However it still isn't showing in the expressions tab once created and loaded. As I said previously there is no heading called "Custom" at all so for the next step in the tutorial I'm a bit stuffed (this is my first time using expressions and functions in QGIS...maybe my last if I can't finish this tutorial!) – Max Oct 24 '16 at 16:52
  • @Max - What QGIS version are you using? Have you considered upgrading to the more latest version? I tested this on QGIS 2.14.3-Essen and it loaded fine. – Joseph Oct 25 '16 at 8:44
  • I've tried it on 2.14.8 Essen and 2.16.3.I think I will uninstall and reinstall - I use OSGeo for installation and I wonder if perhaps something has screwed up somewhere? – Max Oct 25 '16 at 8:57
  • @Max - Could be. Before reinstalling, try deleting the C:/Users/You/.qgis2/python/expressions folder (or back up any scripts that you used). – Joseph Oct 25 '16 at 9:00
  • 1
    Let us continue this discussion in chat. – Max Oct 25 '16 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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