利用arcpy的SearchCursor可以对要素的字段进行操作。以下例子为使用arcpy检查某一字段当中是否存在空值。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 |
# -*- coding:gbk -*- import os,arcpy from arcpy import env def check(mdbpath): mdbnames = [] env.workspace = mdbpath fcs = arcpy.ListFeatureClasses() for fc in fcs: rows = arcpy.SearchCursor(fc," "," "," "," ") for row in rows: try : #数据中有BM这一字段,这里只为检查此字段是否有空值 if row.BM = = None or row.BM = = "": print fc break except : #print fc+"----------no BM" break inputpath = r "F:\最终数据" for root, dir ,files in os.walk(inputpath): for file in files: if file [ - 4 :] = = '.mdb' : mdbpath = os.path.join(root, file ) check(mdbpath) print "Done" |