0

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 ModelBuilder 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 ModelBuilder. 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.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Mar 6, 2013 at 13:08
1
  • 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! Commented Mar 6, 2013 at 15:53

3 Answers 3

2

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.

answered Apr 5, 2013 at 18:22
1
  • @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. Commented Apr 5, 2013 at 18:25
0

I think I did something like this once (not with ModelBuilder), 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).

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered Apr 5, 2013 at 18:08
0

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.)

For a fully-Python approach, the suggestions here may be useful.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered Mar 6, 2013 at 14:02
2
  • Oh, you're summing values from multiple fields, not multiple values in one field -- I misunderstood. Commented Mar 6, 2013 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. Commented Mar 6, 2013 at 16:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.