查找MDB中高程点的高程值有0值的图幅(用游标遍历查找某个字段的值),并将查到的结果写入到TXT中

1、
mdbs = arcpy.ListWorkspaces("*","Access")

2、
 FeatureClasses = arcpy.ListFeatureClasses()

3、
Fields = arcpy.ListFields(FeatureClass)
4、
cursor = arcpy.da.SearchCursor(FeatureClass, 'ELEV')


注意:工作空间的转换

 


import arcpy
from arcpy import env
import os
#input = r"E:\test\MDB"
input = arcpy.GetParameterAsText(0)
env.workspace = input
mdbs = arcpy.ListWorkspaces("*","Access")
for mdb in mdbs:
    #a = ""
    cout = 0
    mdbname = mdb[-14:-4]
    #print mdbname
    env.workspace=mdb
    FeatureClasses = arcpy.ListFeatureClasses()
    for FeatureClass in FeatureClasses:
        if "TERP" in FeatureClass:
            #print FeatureClass
            Fields = arcpy.ListFields(FeatureClass)
            for Field in Fields:
                fieldname = Field.name
                #print fieldname
                if "ELEV" in fieldname:
                    cursor = arcpy.da.SearchCursor(FeatureClass, 'ELEV')
                    for row in cursor:
                        #print(row)
                        if row[0] == 0:
                            #a = mdbname
                            cout = cout+1
                    if cout > 0:
                        arcpy.AddMessage(mdbname+" "+"dgx Elev have 0 problem!")
                        textpath = input+os.sep+"text.txt"
                        f = open(textpath,"a")
                        f.write(mdbname+'\n')
                        f.close()
                        
                            
   # print cout
   # f = open("E:/test/text.txt","a")
    #f.write(a+'\n')
    #f.close()


                    
                

        

 

 

 

posted on 2019-01-14 10:51  太阳花太阳花  阅读(290)  评论(0编辑  收藏  举报