Is there a solution in ArcGIS 10x? Thanks. I used GME (newer Hawth's Tools) and was able to count the number of pixels of any raster class within a vector polygon. I am trying to map crops within a field, so sometimes there can be different classes (crops) within a field polygon. GME spits out class counts as different columns. So if I have 3 raster classes, three count columns. I am looking for a solution to compare the counts of these 3 columns and identify the highest count and attribute that to a new column. I.e. I want to identify the dominant crop within the field. I can look at the column count numbers and identify the dominant class, but this isn't very efficient when you have 100's of fields. Sothing similar is what I am looking for: http://www.get-digital-help.com/2009/07/17/extract-largest-values-from-two-columns-using-array-formula-in-excel/

This still doesn't work and Python gives error. I edited the V#V1 as Canola, V#V2 as Barley, V#V3 as Wheat by adding three new text fields, ![enter image description here][1]and then ran:

GetMaxFieldName({"Canola": !Canola!,"Barley": !Barley!,"Wheat": !Wheat!})

A friend helped me solve it in Excel. 1) Run MAX formula in a new column ("Max"; column O) on the four classes (rows K1:N1) to identify the highest count. 2) Add new column ("Crop", column P) after Max and run: =INDEX($K$1:$N$1,1,MATCH(O2,K2:N2,0))

See image links: http://postimage.org/image/68ham84uv/ http://postimage.org/image/r1sz7e21l/

Let me know if you solve this with Python.

  • Do you want the maximum value for each row (of three columns)? Each row is one field polygon, right? Maybe you can use the Field calculator.
    – nadya
    Commented Nov 22, 2012 at 3:20

2 Answers 2


Am I correct to assume that you have multiple rows of counts per class, much like pictured in the Excel sample you provided? And you want highest count per class or simply highest overall count? (You can actually do both, 'subtotal' highest and overall highest.)

You can use a search cursor to read the row pairs and write them (with an insert cursor) to a new table that can then be easily sorted (and ArcMap has multiple field sort functionality). You would do this, say using your 1st row as an example, by reading 'across' your 3 class example for 3 pairs of values, as in:

classVal1, count1, classVal2, count2, classVal3, count3

..and populating that in your insert table as:

(row 1): classVal1, count1, class1
(row 2): classVal2, count2, class2
(row 3): classVal3, count3, class3

Then reading successive rows, following the pattern above, the 3rd column (field) will behave as a 'counter', reflecting what original class the count values came from, if that is relevant info you need....

So, after writing the output table, you can easily sort descending by count to get the highest overall count and corresponding classVal...or sort by count and class to get the highest counts per class and corresponding classVals. Is that what you need?

And, as a further note, you can actually use a sort in conjunction with the search cursor on this result to output the highest values if max value(s) are all you wish as final output, or if you have a preference for the summary statistics or frequency tools, use them instead.

  • Wayne, can you review the image link that I shared and then explain your method with some examples? Thanks. Commented Nov 22, 2012 at 5:07
  • OK, I saw your pic and it looks like you're trying to find the max value of 4 fields in the same row, place this Val Commented Nov 22, 2012 at 5:31
  • Accidentally submitted that last comment prematurely... Yes, you can use the field calculator to fetch the 4 values, compare them for the largest to populate your Dom crop field. Use the greater than operator (>), retaining the value that evaluates true. See the field calculator examples. You'll need the 'advanced' pre-logic script code. Commented Nov 22, 2012 at 5:43
  • I read and I like what Nadya provided... I don't think Python will accept your '#' characters, so try renaming your fields, maybe taking it out or replacing with something line an underscore '_'. Then try the call again: GetMaxFieldName({"V_V1": !V_V1!...etc. Commented Nov 22, 2012 at 6:18

Assuming that each row is one crop field polygon, and you want the maximum value of the three count columns (for each row). You can simply use the Python built-in function max in the Field calculator.

Firstly add a new field, then calculate the maximum value for each record from the list of fields (your count columns):

max([!field1!, !field2!, !field3!])

Other field calculator examples.

To see which field name contains the highest value, try this advice (at the end of the thread)

Hope this can be useful.

  • Thanks to @nadya and Wayne. I tried nadya's tip, but this just identifies the highest class count in a row. I need the name of that highest class too. Your tip is similar to the MAX formula in Excel. I guess I can do this in Excel and join it to my shapefile. Please see: postimage.org/image/6ygh7rknb Commented Nov 22, 2012 at 5:04
  • To get the field name (V1, V2 or V3) with that maximum value, try this advice (at the end of the thread) forums.arcgis.com/threads/…
    – nadya
    Commented Nov 22, 2012 at 5:17
  • I tried this by replacing with V#V. It didn't work... GetMaxFieldName({"V#V1": !V#V1!,"V#V2": !V#V2!,"V#V3": !V#V3!}) Commented Nov 22, 2012 at 5:46
  • 1
    I think Python is tripping on the '#' character. Commented Nov 22, 2012 at 6:20
  • Yes, '#' usually is a comment sign in Python. Try with another field names.
    – nadya
    Commented Nov 22, 2012 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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