Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am using ArcGIS 10. I have a little experience with python but i feel that python in ArcGIS is slightly different. VB will work fine as well.

Problem: I have n different columns called 'percent_1', 'percent_2','percent_3' and 'percent_4'.... 'percent_n'. They contain percentages. I have a new field called 'Class_t'. I want to check which one among 'percent_1..n' is highest and then want to put 'x' in 'Class_t' field.

If more information is required, feel free to inquire. I need it asap. Its final step of my project.

Thanks a lot in advance.

Cheers Ns

share|improve this question
    
It's good form to accept answers NSoni btw - Hope this has helped btw. –  Hairy Oct 13 '11 at 9:58

3 Answers 3

Personally, I'd go python all the way

cursor = arcpy.searchcursor(your_table)
for row in cursor:
    sort = sorte([row.percent_1,row.percent_2,row.percent_3,row.percent_4])            
    row.Class_t = sort[len(sort)-1]
    cursor.updateRow(row)
    del row

del cursor

Play about with it in Idle, it's something like this.

share|improve this answer
    
Thanks for a quick response Hairy. But I think I should edit my question, because I might have variable number of percent_x, eg. 3,4,5. Is it possible to include this information? –  NSoni Oct 13 '11 at 10:32
    
Just add as many as you need, do a count on the fields and then loop the name into a list i.e. for columns in table - if left(colname,8) == "percent_" then mylist.append(col) or something The sort is done on the list, so make sure you capture each column that is like percent_ Very easy really –  Hairy Oct 13 '11 at 10:45
1  
@Hairy, No need to sort... (can't get the lines to format properly but ... >>> a = [5,3,2,1,9,11,12] >>> max(a) 12 >>> –  Dan Patterson Oct 13 '11 at 12:24
    
Thanks a lot again. I figured other way to solve my problem. –  NSoni Oct 13 '11 at 13:31
1  
@NSoni, if you asked the question and found another solution yourself, you should post your solution as another answer so others can learn from it. This community is based upon give/take. –  RyanDalton Oct 13 '11 at 14:29

Soni,

In python Try to write your fields to a single list and use the max to get the maximum of the fields. Then you may use this max value to update the field you want. I dont have exact same method as your are working but I've a code for writing all the columns in a field to single list then finding the max value from it. Look at the code:

import arcpy

workspace = "C:\Data\States\States.shp"

fieldlist = arcpy.ListFields(workspace)

List = []

fc = arcpy.SearchCursor(workspace)

Total = 0

for row in fc: x = row.getValue("FID") List += [x] Total += int(x) rows.next()

print List print Total print max(List) print len(List) avg = Total/len(List) print avg

share|improve this answer

Here is exact answer you are looking. Let me know if it solves your problem. Seeya

import arcpy

workspace = "C:\Data\States\States.shp"

fieldlist = arcpy.ListFields(workspace)

List = []

fc = arcpy.SearchCursor(workspace)

fc = arcpy.UpdateCursor(workspace) Total = 0

for row in fc: a = int(row.getValue("FID")) b = int(row.getValue("Region")) c = int(row.getValue("Division")) d = int(row.getValue("STATEFP")) List = [a,b,c,d] print List e = max(List) print e row.Max = e fc.updateRow(row) fc.next()

share|improve this answer
    
Thanks a lot. I already fixed it so i didnt use it. –  NSoni Dec 14 '11 at 15:41

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.