[Gvsig_english] Field Calculator: look for an expression saved in a file

Antonio Falciano afalciano at yahoo.it
Fri Sep 27 10:18:44 CEST 2013


Il 27/09/2013 09:43, phil_murcia ha scritto:
> Hi Antonio,
>
> Thanks so much for the advice. It seems once you get to grips with the
> Jython functions you gain a lot of capabilities. However I cannot get my
> expression to work, without wanting to turn this extremely useful thread
> into a troubleshooting discussion, I cannot work out why.
>
> I have created my .py file, and switched in all the correct headings (I have
> also checked for line errors in spyder environment). In gvSIG I begin
> editing the layer, open the attribute table, select the 'compat' column and
> then open the expression calculator. I then go to the advance tab and
> explore for the correct .py file, on loading this I am still unable to click
> 'ok' and the 'evaluate' seemingly still does nothing. With the .py loaded I
> then tried switching back to the general tab and entering the second
> expression "compat([Agr],[Urb],[For],[Com],[Pub])" - but when I then try and
> click ok I then get an error expression with a traceback description.
>
> I am not implementing the expression correctly or am I missing something
> obvious?

Hi Phil,
sorry, I haven't tested the script yesterday. You can try with the
script in attachment in order to respect the right indentation. I have
also substituted the "for" reserved word with "fore". Hope this helps!

Cheers,
Antonio

-- 
Antonio Falciano
http://www.linkedin.com/in/antoniofalciano
-------------- next part --------------
def compat(agr,urb,fore,com,pub,lub):
  if lub=="Agr":
    result=agr
  elif lub=="Urb":
    result=urb
  elif lub=="For":
    result=fore
   elif lub=="Com":
    result=com
  elif lub=="Pub":
    result=pub
  else:
    result=-1
  return result 


More information about the Gvsig_internacional mailing list