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

iaborsi borsi at math.unifi.it
Tue Dec 13 10:28:39 CET 2011


Hi Antonio,
thanks a lot! I've tried that: very easy, and it works perfectly!
I take this opportunity to make an additional question: if in writing 
this Jython function I need additional Modules  (typically an original 
group of functions defined by myself) which is the right path to save 
this stuff? I guess is the same directory from which I upload my Jython 
function, isn't it?
To be clearer (following you example below): I want to modify your 
example script "conversion.py" in this way:
-------
from MyNewModule import *

def m2tokm2(value):
   temp=value/1000000
   result = MyNewFunction(temp)
   return result
------- 
where MyNewFunction() is defined within the module MyNewModule.

I guess I have to save the module within the same path of conversion.py. 
Right?

Thanks again and best regards,
I.

-- 
Iacopo Borsi
Dipartimento di Matematica U.Dini
Università di Firenze.
V.le Morgagni 67/A
50134 Firenze - Italy
Tel. +39.0554237147
Fax. +39.0554237133
e-mail borsi at math.unifi.it
Web:   http://web.math.unifi.it/users/borsi
http://sidgrid.isti.cnr.it



 
Antonio Falciano [via OSGeo.org] wrote:
> 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
> _______________________________________________
> Gvsig_internacional mailing list
> [hidden email] </user/SendEmail.jtp?type=node&node=7089143&i=0>
>
> To see the archives, edit your preferences or unsubscribe from this 
> mailing list, please access this url:
>
> http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional
>
>
> ------------------------------------------------------------------------
> If you reply to this email, your message will be added to the 
> discussion below:
> http://osgeo-org.1803224.n2.nabble.com/Field-Calculator-look-for-an-expression-saved-in-a-file-tp7086102p7089143.html 
>
> To start a new topic under gvSIG users, email 
> ml-node+s1803224n2009903h67 at n2.nabble.com
> To unsubscribe from gvSIG users, click here 
> <http://osgeo-org.1803224.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=2009903&code=Ym9yc2lAbWF0aC51bmlmaS5pdHwyMDA5OTAzfC01MjEyNTE4ODM=>.
> NAML 
> <http://osgeo-org.1803224.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.InstantMailNamespace&breadcrumbs=instant+emails%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> 
>




--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Field-Calculator-look-for-an-expression-saved-in-a-file-tp7086102p7089278.html
Sent from the gvSIG users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserv.gva.es/pipermail/gvsig_internacional/attachments/20111213/1203fd2a/attachment.htm 


More information about the Gvsig_internacional mailing list