方法
ArcGIS Pro では、フィールド演算 (Calculate Field) ツールの sum() 関数を使用して、数値フィールドのリストから各レコードの合計を計算できます。 ただし、フィーチャクラスまたはテーブルに多数のフィールドが含まれている場合、すべての数値フィールドを手動で選択することは非現実的です。
この記事に記載されている ArcPy スクリプトを使用して、フィーチャクラスまたはテーブル内のすべての数値フィールドの値の合計を計算できます。
この例では、次の図に示すように、「Point1」フィーチャクラスには 5 つの数値フィールドがあります。

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)
各フィーチャの数値フィールドの合計が、新しいフィールド「SumField」に入力されました。

記事 ID: 000029132
ArcGIS エキスパートのサポートを受ける
今すぐチャットを開始