1

Today at work I was facing some challenges to Label the count values from attribute tables of the feature class. We have all the data stored in geodatabase that is server based. I wrote python code in label expression that did not work out. Challenge is I have a field whose value are repeating,and I want to plot those how many times these values are repeating. Please see below image, Attribute field example

On above image, I want to label A(2), B(2), C(3), D(1). So on the bracket it should show count values.

How to do with the feature class stored in geodatabse that is connection based?

1 Answer 1

4

This

def FindLabel ( [Label] ):
  mxd = arcpy.mapping.MapDocument("CURRENT")
  lyr = arcpy.mapping.ListLayers(mxd,"TARGET")[0]
  q='"LABEL"='+"'"+[LABEL]+"'"
  tbl=arcpy.da.TableToNumPyArray(lyr,"LABEL",q)
  n=len(tbl)
  return '%s(%s)' %([LABEL],str(n))

is tested on shapefile:

enter image description here

RESULT

enter image description here

1
  • Thank you For the code, I will test on the geodatabase and will update you. Code looks great. Commented Dec 5, 2015 at 4:01

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