I am trying to conduct a multicriteria evaluation, and it is necessary to check the compatibility of two different land-use types that I have in seperate layers. I am working in gvSIG 1.12, and have a unioned layer which contains polygons which are made up of land use A and B, included in the table is compatibility of Land-use A with each instance of B, but I need to create a final column that can select the correct number. An example of my attribute table is shown below.


ID  |  Land-use A |  Agr  |  Urb  | For  | Com |  Pub | Land-use B | Compat
 1       N           1        4      3      0      2      Agr               
 2       G           2        3      5      1      0      Pub
 3       K           4        2      3      5      1      Urb
 4       N           1        4      3      0      2      Urb

I am particularly struggling with getting the syntax correct for the Expression calculator. Should this be feasable using the preset commands in gvSIGs expression calculator or do I need to import the expression from a file (for instance a .py). In excel this is a simple if statement does the job but I am unable to execute this in gvSIG.

An example of my desired attribute table can be seen below:


ID  |  Land-use A |  Agr  |  Urb  | For  | Com |  Pub | Land-use B | Compat
 1       N           1        4      3      0      2      Agr          1     
 2       G           2        3      5      1      0      Pub          0
 3       K           4        2      3      5      1      Urb          2
 4       N           1        4      3      0      2      Urb          4
  • That's interesting, I'll forward your query to the mailing list. I'm not sure for the 1.12 field calculator, but that should be easy on the gvSIG 2.0 new scripting.
    – Jorge Sanz
    Sep 27, 2013 at 8:32
  • Done, if anything useful is posted there we can place it here for future reference.
    – Jorge Sanz
    Sep 27, 2013 at 8:51
  • I have found a solution to this problem, predominantly from help via the aforementioned mailing list. A Jython function is required, similar to this: def COMPAT(Agr,Urb,For,Com,Pub,LanduseB): if LanduseB=="Agr": result=Agr elif LanduseB=="Urb": result=Urb elif LanduseB=="For": result=For elif LanduseB=="Com": result=Com elif LanduseB=="Pub": result=Pub else: result=-1 return result This is loaded via the advanced tab in the expression calculator, and then in the general tab the following is entered: Sep 27, 2013 at 12:12
  • COMPAT([Agr],[Urb],[For],[Com],[Pub],[LanduseB]) Sep 27, 2013 at 12:13
  • IMHO the easiest way to accomplish this task is the simple expression in the Field Calculator. I answered to your question reporting both solutions I wrote in the gvSIG International mailing list. Sep 29, 2013 at 17:31

2 Answers 2


The problem can be solved in two alternative ways:

1. simple expression:

([Land-use B]=="Agr")*[Agr]+([Land-use B]=="Urb")*[Urb]+([Land-use B]=="For")*[For]+([Land-use B]=="Com")*[Com]+([Land-use B]=="Pub")*[Pub]

Note: result=0 if [Land-use B] is not equal to "Agr" or "Urb" or "For" or "Com" or "Pub".

2. advanced expression (via Jython scripting):

def compat(agr,urb,fore,com,pub,lub):
    if lub=="Agr":
    elif lub=="Urb":
    elif lub=="For":
    elif lub=="Com":
    elif lub=="Pub":
    return result

Note: result=0 in the 'else' case.

Save this Jython function in a script with .py extension (e.g. compat.py), select the header of Land-use B column in the attribute table, click on the Field Calculator, select the Advanced tab, load and process the script and finally type the following expression:

compat([Agr],[Urb],[For],[Com],[Pub],[Land-use B])

i try to do this with Scripting for gvSIG 2.0 Also i explain better this example in this post here

Some part is in english, but if you need more help i'll be glad to explain you better. The code should be like this, but i'm having one problem that gvSIG doesn't allow me to save the changes, that mean i can't close the edition mode in the table, i hope you don't have this problem, if anyone can help that would be great. This is why in the code appear the line #ERROR document.commit(), if you want to try just delete "#ERROR"

from gvsig import *

def main():
    #We work with our active document
    document = currentDocument()
    features = document.features()
    #Edit mode

    #Features in our table
    for feature in features:
        #Column name
        var = feature.get("Land-use B")
        value = feature.get(var)
        #Here the column that we want modify
        #Update the changes

    #ERROR document.commit()
    print "END"

This script just will update the table when you run the script. It's different than having a field calculator but well, now you can choose whatever you prefer. Hope this is helpfull for you

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.