2

I'm a student at Millersville University, PA studying for a BA in Geography with a concentration in GIS. I've stumbled across this site for questions I've had over the past year or so with getting introduced to ArcGIS.

I have come across a problem that I can't figure out and my textbook didn't offer any help so I'm hoping one of you can.

I have a table which consists of 3 attribute joins, and I have a text field which has 2 unique values. I want to create a field in which I can summarize the number of times a particular text occurs.

For Example: Jx = Join #

ObjectID 1 |J1: A | J2: A | J3: B | CountFldA: 2
ObjectID 2 |J1: B | J2: B | J3: A | CountFldA: 1

I have a feeling that the answer lies somewhere in python but I have no formal experience in it.

4
  • welcome to the site! Have you taken a look at the frequency tool? Commented Sep 27, 2012 at 4:59
  • @ Stephen Lead Close, the frequency is defined on the link you gave as _"Reads a table and a set of fields and creates a new table containing unique field values and the number of occurrences of each unique field value."_ What I'm looking for is the frequency across the record. Instead of counting down, I'm counting across. Complicated by the fact that it's a text field.
    – wxmeddler
    Commented Sep 27, 2012 at 7:44
  • ah, that makes sense - sorry I missed that crucial detail. The way to approach this will be to iterate through each record using an ArcPy SearchCursor, and analyse the values in-memory. I'll write some pseudo-code in the morning if you haven't solved it by then :) Commented Sep 27, 2012 at 10:11
  • Rayner's answer is great - I should have said "one way to approach this" since his is faster. Commented Sep 27, 2012 at 22:49

1 Answer 1

1

You could concatenate multiple fields together into a new combined field and use 'InStr' inside the Field Calculator (VBScript) to count the number of occurrences of a specific character or string. For example, instr([Combined],"A") would return the number of "A"s in the Combined field. Or I suppose you could use InStr on each individual joined field and then add them up. instr([Field1],"A") + instr([Field2,"A") and so on.

1
  • 1
    Perfect @Rayner! This did exactly what I wanted... The VBscript ended up looking like: InStr( [cd111.PARTY] , "Democrat") + InStr( [cd110.PARTY], "Democrat" ) +InStr( [cd109.PARTY] , "Democrat" )
    – wxmeddler
    Commented Sep 27, 2012 at 13:22

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.