ArcGIS中使用字段计算器生成随机数和自增数

当我们使用ArcGIS,在编辑字段或者有某种数据处理需求时,想要新建个字段生成一列随机数或者自增序列数,
下面是实现得过程和代码:
首先新建个字段,字段类型是整型或者浮点或者双精度
ArcGIS中使用字段计算器生成随机数和自增数
(1)生成随机数

ArcGIS中使用字段计算器生成随机数和自增数

1
2
3
4
import random
def randnum():
res=random.randint(1,10)
return res

(2)自增序列数
ArcGIS中使用字段计算器生成随机数和自增数

1
2
3
4
5
6
7
8
total = 0
def accumulate(increment):
global total
if total:
total += increment
else:
total = increment
return total

PS;注意选择是python脚本,以及代码的缩进。

结果如下:
ArcGIS中使用字段计算器生成随机数和自增数