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

Antonio Falciano afalciano at yahoo.it
Tue Dec 13 09:36:30 CET 2011


Il 12/12/2011 14.39, iaborsi ha scritto:
> Hi,
> I'm quite new with gvSIG.
> This is my question.
> I wish to write a specific "expression" as Python script, to be used
> in the Field Calculator (after starting an editing session).
> Reading through the Manual, I see that it is possible just saving this
> script in a Python file and uploading it from the appropriate box:
> Field Calculator > Advanced tab.
> I've done it, also using some dummy script, but it doesn't work.
> Can anybody post some explicit example of using this feature?

Iacopo,
you have simply to define a Jython function which returns the result of
your calculation, load it from the Advanced tab and finally use that
function as the built-in functions of the Field Calculator.
For instance, if we have a field containing the area expressed in square
meters (e.g. SUP_M2) and we want to convert it in square kilometers,
we can write:

def m2tokm2(value):
   result=value/1000000
   return result

We save this script as conversion.py, load it from the Advanced tab
and then we can use the Jython function writing in correspondence of
a new field called e.g. SUP_KM2:

m2tokm2([SUP_M2])

Finally, the field SUP_KM2 will be populated by area expressed in km^2.

ciao
Antonio

-- 
Antonio Falciano
http://www.linkedin.com/in/antoniofalciano


More information about the Gvsig_internacional mailing list