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 think my problem is easy to solve, but so far I couldn't find a solution. I have a Feature Dataset created with the Union tool in Model Builder and now try to sum up all values of one specific field (VSG_EINZEL->up to 150 fields) into a new field (VSG_ALL) automatically in Model Builder. My problem is, that the number of VSG_EINZEL-fields is rather high and varies so I can’t use a static field calculaion like: VSG_ALL = VSG_EINZEL + VSG_EINZEL_1 + VSG_EINZEL_12 and so on. I am very new in using Python and I really appreciate any help and suggestions.

Thank you very much in advance!

Michaela

share|improve this question
    
Thanks for your help, but, unfortunately I need do forward the sum of each row to a specific field since this calculation is part of a Model Builder application. Are there any other suggestions? Thank you very much in advance! –  Michaela Mar 6 '13 at 15:53

3 Answers 3

I would go the route of using cursors. I'm not sure of the field names that you are using, but something like this should work assuming that the VSG_EINZEL fields are numerical:

import arcpy
# use workspace env or give an absolute path for fc
arcpy.env.workspace = "workspace"
fc = "feature_class"

# making a list of fields that contain VSG_EIZEL
# ex VSG_EINZEL, VSG_EIZEL_1, VSG_EIZEL_2
field_prefix = "VSG_EINZEL"
field_list = []
f_list = arcpy.ListFields(fc)
for f in f_list:
    if field_prefix in f.name:
        field_list.append(f.name)

# use update cursor to find values
# and update the total field
rows = arcpy.UpdateCursor(fc)
for row in rows:
    VSG_SUM = 0
    for f in field_list:
        VSG_SUM += row.getValue(f)
    row.VSG_ALL = VSG_SUM
    rows.updateRow(row)
    del VSG_SUM
del rows

It might need a little adjusting to fit your needs.

share|improve this answer
    
@myself - I just realized that you, Michaela, were wanting to go through model builder. If you would want to go through python instead, take a look above. –  gm70560 Apr 5 '13 at 18:25

The Summary Statistics tool (in the Analysis Tools | Statistics toolbox) is probably what you're looking for. You can specify that particular field (VSG_EINZEL) and the statistic you want (SUM); it can work with however many values you have in VSG_EINZEL.

The output is a table, which may not be ideal for further calculations -- but hopefully this at least gets you further along. (If you want to do this in Python rather than via Arc tools, the approach would be different, but you could get a numerical value rather than a table.)

edited to add: For a fully-Python approach, the suggestions here may be useful.

share|improve this answer
    
Oh, you're summing values from multiple fields, not multiple values in one field -- I misunderstood. –  Erica Mar 6 '13 at 16:30
    
What if you use a Merge operation (Data Management | General) instead of Union? This would bring all your individual polygon features into one multipolygon feature, but instead of unique VSG_EINZEL fields for each one (VSG_EINZEL1, VSH_EINZEL2, etc.), the data would be collated into a single VSG_EINZEL field, making summation easier. –  Erica Mar 6 '13 at 16:43

I think I did something like this once (not with model builder), I just added a new field and created a sum of the attributes I was interested in; then I used the summarize function to get a table about my results. In my case, I was after minimum and maximum values as well as the sum so I needed three new fields (and I think I had all kinds of headaches because I didn't even think about the possibility of a tie in the data).

share|improve this answer

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.