-2

I am doing hydrology analysis in ArcMap 10.2 and have a drainage area feature class containing hundreds of records. Each record is assigned a drainage area name and acreage amount.

How do I sum all the acreage amounts for each drainage area name using a python script preferably in the field calculator?

closed as off-topic by PolyGeo Jan 19 '17 at 5:26

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • gis.stackexchange.com/questions/118628/… may provide some ideas. – Richard Morgan Jan 18 '17 at 21:10
  • arcpy.Dissolve_management(feature_class,outputname,[drainage_field or fields],['Acres','SUM']) – ziggy Jan 18 '17 at 21:17
  • Welcome to GIS SE! As a new user be sure to take the Tour. For questions that involve code we ask that you show us where you are stuck with your own code by including a code snippet (or in this case an expression and code block) in your question. There is an edit button beneath your question which will enable you to do that and a {} button that enables you to format any highlighted code nicely. – PolyGeo Jan 19 '17 at 5:26
3

If you do not necessarily need to use python to do this, you can use the Summary Statistics (Analysis) tool.

http://resources.arcgis.com/en/help/main/10.1/index.html#//00080000001z000000

Select your acreage field as the Statistics Field(s) with a Statistic Type of SUM, and select your drainage area name field as the Case Field.

  • I agree - the Field Calculator is the wrong tool for trying to do this, irrespective of whether it can be done using it. – PolyGeo Jan 19 '17 at 5:25
1

You can do this, somewhat cumbersomely, in the field calculator like:

Parser: Python

Expression:

my_func(!YOUR_GROUP_FIELD!)

Codeblock:

def my_func(group):
  fc = 'YOUR_FEATURE_LAYER'
  sum_field = 'YOUR_SUM_FIELD'
  group_field = 'YOUR_GROUP_FIELD'
  wc = "{0} = {1}".format(arcpy.AddFieldDelimiters(fc,group_field),group)
  return sum([i[0] for i in arcpy.da.SearchCursor(fc,sum_field,wc)])

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