Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I got table like that one (Example).

I need to change 0 to 1 and -1 to 0 in each field except first and second.

The problem is that every time i have different number of fields and field name is changed too, but i can use wildcard "FID_" to select a field name.

I read some stuff about, should be like that:

 def test(field.name):
  fieldList = ListFields(%path%)
  for field in fieldList:
    if (field.name)==0:
      EQ=1
    else:
      EQ=0
    return EQ

%path% should be the value taken from model-builder (if that is possilbe).

share|improve this question
    
If your preference is ModelBuilder, think about Iterators and Model Only Tools like Calculate Value, or if it is Python/ArcPy, then I think you will need to use getValue and setValue. – PolyGeo Sep 26 '12 at 11:06
    
Why not just do this in field calculator? You could use the same snippet in each field and skip modelbuilder all together. – Roy Sep 26 '12 at 11:54

This would be difficult to do in modelbuilder as there is no iterator that iterates over columns. This would be much easier if done in Python, using as @Roy says the field calculator. Below is the required code:

import arcpy
myTable = r"C:\Temp\New_dBASE_Table.dbf"
fields = arcpy.ListFields(myTable)
for f in fields:
    if f.name[:4] == "FID_":
        print "Processing " + f.name
        exp = "change(!" + f.name + "!)"
        # The code assumes if it is not zero then it must be -1
        arcpy.CalculateField_management(myTable, f.name, exp, "PYTHON_9.3", "def change(v):\n  if v == 0:\n    return 1\n  else:\n    return 0")
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.