計算順序編號
# 計算順序編號 # 可訪問 esriurl.com/CalculatorExamples 獲取更多計算器示例 rec=0 def SequentialNumber(): global rec pStart = 1 pInterval = 1 if (rec == 0): rec = pStart else: rec = rec + pInterval return rec
累加計算和順序計算
根據某間隔值計算順序 ID 或數字。
表達式:
autoIncrement()
代碼塊:
rec=0
def autoIncrement():
global rec
pStart = 1 #adjust start value, if req'd
pInterval = 1 #adjust interval value, if req'd
if (rec == 0):
rec = pStart
else:
rec = rec + pInterval
return rec
計算數值型字段的累加值。
表達式:
accumulate(!FieldA!)
代碼塊:
total = 0
def accumulate(increment):
global total
if total:
total += increment
else:
total = increment
return total
計算數值型字段的百分比增量。
表達式:
percentIncrease(float(!FieldA!))
代碼塊:
lastValue = 0
def percentIncrease(newValue):
global lastValue
if lastValue:
percentage = ((newValue - lastValue) / lastValue) * 100
else:
percentage = 0
lastValue = newValue
return percentage
隨機值
通過 numpy 站點包來計算 0.0 和 1.0 之間的隨機浮點值。
表達式:
getRandomValue()
代碼塊:
import numpy
def getRandomValue():
return numpy.random.random()
使用隨機模塊來計算 0 與 10 之間的隨機整數。
表達式:
random.randint(0, 10)
代碼塊:
import random
計算空值
在 Python 表達式中,可通過 Python None 來計算空值。

僅當該字段為空時,才可以進行以下計算。
使用 Python None 計算空值。