Hi Antonio,
<br/>thanks a lot! I've tried that: very easy, and it works perfectly!
<br/>I take this opportunity to make an additional question: if in writing
<br/>this Jython function I need additional Modules (typically an original
<br/>group of functions defined by myself) which is the right path to save
<br/>this stuff? I guess is the same directory from which I upload my Jython
<br/>function, isn't it?
<br/>To be clearer (following you example below): I want to modify your
<br/>example script "conversion.py" in this way:
<br/>-------
<br/>from MyNewModule import *
<br/><br/>def m2tokm2(value):
<br/> temp=value/1000000
<br/> result = MyNewFunction(temp)
<br/> return result
<br/>-------
<br/>where MyNewFunction() is defined within the module MyNewModule.
<br/><br/>I guess I have to save the module within the same path of conversion.py.
<br/>Right?
<br/><br/>Thanks again and best regards,
<br/>I.
<br/><br/>--
<br/>Iacopo Borsi
<br/>Dipartimento di Matematica U.Dini
<br/>Università di Firenze.
<br/>V.le Morgagni 67/A
<br/>50134 Firenze - Italy
<br/>Tel. +39.0554237147
<br/>Fax. +39.0554237133
<br/>e-mail <a href="/user/SendEmail.jtp?type=node&node=7089278&i=0" target="_top" rel="nofollow" link="external">[hidden email]</a>
<br/>Web: <a href="http://web.math.unifi.it/users/borsi" target="_top" rel="nofollow" link="external">http://web.math.unifi.it/users/borsi</a><br/><a href="http://sidgrid.isti.cnr.it" target="_top" rel="nofollow" link="external">http://sidgrid.isti.cnr.it</a><br/><br/><br/><br/>
<br/>Antonio Falciano [via OSGeo.org] wrote:
<div class='shrinkable-quote'><br/>> Il 12/12/2011 14.39, iaborsi ha scritto:
<br/>>
<br/>> > Hi,
<br/>> > I'm quite new with gvSIG.
<br/>> > This is my question.
<br/>> > I wish to write a specific "expression" as Python script, to be used
<br/>> > in the Field Calculator (after starting an editing session).
<br/>> > Reading through the Manual, I see that it is possible just saving this
<br/>> > script in a Python file and uploading it from the appropriate box:
<br/>> > Field Calculator > Advanced tab.
<br/>> > I've done it, also using some dummy script, but it doesn't work.
<br/>> > Can anybody post some explicit example of using this feature?
<br/>>
<br/>> Iacopo,
<br/>> you have simply to define a Jython function which returns the result of
<br/>> your calculation, load it from the Advanced tab and finally use that
<br/>> function as the built-in functions of the Field Calculator.
<br/>> For instance, if we have a field containing the area expressed in square
<br/>> meters (e.g. SUP_M2) and we want to convert it in square kilometers,
<br/>> we can write:
<br/>>
<br/>> def m2tokm2(value):
<br/>> result=value/1000000
<br/>> return result
<br/>>
<br/>> We save this script as conversion.py, load it from the Advanced tab
<br/>> and then we can use the Jython function writing in correspondence of
<br/>> a new field called e.g. SUP_KM2:
<br/>>
<br/>> m2tokm2([SUP_M2])
<br/>>
<br/>> Finally, the field SUP_KM2 will be populated by area expressed in km^2.
<br/>>
<br/>> ciao
<br/>> Antonio
<br/>>
<br/>> --
<br/>> Antonio Falciano
<br/>> <a href="http://www.linkedin.com/in/antoniofalciano" target="_top" rel="nofollow" link="external">http://www.linkedin.com/in/antoniofalciano</a><br/>> _______________________________________________
<br/>> Gvsig_internacional mailing list
<br/>> [hidden email] </user/SendEmail.jtp?type=node&node=7089143&i=0>
<br/>>
<br/>> To see the archives, edit your preferences or unsubscribe from this
<br/>> mailing list, please access this url:
<br/>>
<br/>> <a href="http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional" target="_top" rel="nofollow" link="external">http://listserv.gva.es/cgi-bin/mailman/listinfo/gvsig_internacional</a><br/>>
<br/>>
<br/>> ------------------------------------------------------------------------
<br/>> If you reply to this email, your message will be added to the
<br/>> discussion below:
<br/>> <a href="http://osgeo-org.1803224.n2.nabble.com/Field-Calculator-look-for-an-expression-saved-in-a-file-tp7086102p7089143.html" target="_top" rel="nofollow" link="external">http://osgeo-org.1803224.n2.nabble.com/Field-Calculator-look-for-an-expression-saved-in-a-file-tp7086102p7089143.html</a>
<br/>>
<br/>> To start a new topic under gvSIG users, email
<br/>> <a href="/user/SendEmail.jtp?type=node&node=7089278&i=1" target="_top" rel="nofollow" link="external">[hidden email]</a>
<br/>> To unsubscribe from gvSIG users, click here
<br/>> <<a href="" target="_top" rel="nofollow" link="external">
<br/>> NAML
<br/>> <<a href="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" target="_top" rel="nofollow" link="external">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</a>>
<br/>>
</div><br/><br/>
        
<br/><hr align="left" width="300" />
View this message in context: <a href="http://osgeo-org.1803224.n2.nabble.com/Field-Calculator-look-for-an-expression-saved-in-a-file-tp7086102p7089278.html">Re: Field Calculator: look for an expression saved in a file</a><br/>
Sent from the <a href="http://osgeo-org.1803224.n2.nabble.com/gvSIG-users-f2009903.html">gvSIG users mailing list archive</a> at Nabble.com.<br/>