HOW TO
In ArcGIS Pro kann die Funktion sum() des Werkzeugs "Feld berechnen" verwendet werden, um aus einer Liste numerischer Felder die Summe für jeden Datensatz zu berechnen. Enthält die Feature-Class oder Tabelle jedoch eine große Anzahl von Feldern, ist es umständlich, alle numerischen Felder manuell auszuwählen.
Mit dem in diesem Artikel bereitgestellten ArcPy-Skript kann für alle numerischen Felder, die in einer Feature-Class oder Tabelle enthalten sind, die Summe der Werte berechnet werden.
In diesem Beispiel enthält die Feature-Class "Point1" fünf numerische Felder, wie in der nächsten Abbildung zu sehen ist.

import arcpy
# Set the path to the feature class or the table
table = r""
# Add a new field to the table
arcpy.management.AddField(table, "SumField", "DOUBLE")
# Use UpdateCursor to iterate through the rows of the table
with arcpy.da.UpdateCursor(table, "*") as cursor:
for row in cursor:
# Initialize a variable to store the sum
total = 0
# Iterate through each field in the row
for i in range(len(row)):
# Check if the field is numeric and not OBJECTID, Shape_Length, and Shape_Area
if isinstance(row[i], (int, float, complex)) and cursor.fields[i] not in ['OBJECTID', 'Shape_Length', 'Shape_Area']:
# Add the field's value to the total
total += row[i]
# Update the new field with the total
row[cursor.fields.index('SumField')] = total
cursor.updateRow(row)
Die Summe der numerischen Felder für jedes Feature wird nun in das neue Feld "SumField" eingetragen.

Artikel-ID: 000029132
Unterstützung durch ArcGIS-Experten anfordern
Beginnen Sie jetzt mit dem Chatten