Delete a GIS database empty layer (Gdb,mdb,shape)

Source: Internet
Author: User

Bulk delete the GIS database empty layer.

#-*-coding:utf-8-*-# ---------------------------------------------------------------------------#merge.py#Created on:2013-01-21 10:25:22.00000#(generated by wanglin_tjch)#Description:# ---------------------------------------------------------------------------#Import arcpy ModuleImportarcpyImportOs.pathImport TimeImportRandom fromarcpyImportEnvfcdbdir="d:\\aaa"DICALLFC={}fcall=[]gdballpath=[]if  notisinstance (fcdbdir,unicode): Fcdbdir= Fcdbdir.decode ('Utf-8')#Get Dataset and Featureclass,store in Dicallfc,key =fc value= DSifos.path.exists (fcdbdir): forDirpath,dirnames,filenamesinchOs.walk (fcdbdir):#Traverse gdb folder to get GDB         forDirNameinchDirnames:if ". GDB" inchDirname:gdbfilepath=Os.path.join (dirpath,dirname)if  notGdbfilepathinchGDBAllPath:GDBAllPath.append (Gdbfilepath)#Iterate MDB folder get MDB         forFileNameinchFilenames:ifOs.path.splitext (filename) [1]=='. mdb': Mdbfilepath=Os.path.join (dirpath,filename)if  notMdbfilepathinchGDBAllPath:GDBAllPath.append (Mdbfilepath)#Traverse shp folder to get shape         forFileNameinchFilenames:ifOs.path.splitext (filename) [1]=='. SHP': Shpfilepath=Os.path.join (dirpath,filename)if  notDirpathinchGDBAllPath:GDBAllPath.append (Dirpath) forEveryfilepathinchGDBAllPath:env.workspace=Everyfilepath singlefclist= arcpy. Listfeatureclasses (""," All")        ifSinglefclist andLen (singlefclist) >0: forSinglefcinchsinglefclist:#if SINGLEFC is Unicode then do not change, otherwise utf-8 SINGLEFC encoding is decoded to Unicode                if  notisinstance (singlefc,unicode): SINGLEFC= Singlefc.decode ('Utf-8')                ifisinstance (everyfilepath,unicode): Fcfullpath= everyfilepath+"\\"+SINGLEFCElse: Fcfullpath= everyfilepath+"\\"+singlefc.encode ('gb2312') Rows= arcpy. Searchcursor (Fcfullpath,"","","","") Count=0 forFeaturecountinchRows:count=count+1ifCount = =0:arcpy. Delete_management (Fcfullpath)Print "Delete"+fcfullpath+"succeed at"+time.strftime ("%y-%m-%d%x", Time.localtime ()) Datasetlist= arcpy. Listdatasets ("","Feature")         forDataSetinchdatasetlist:#If the dataset is Unicode, it does not change, otherwise the Utf-8 dataset encoding is decoded to Unicode            ifisinstance (dataset,unicode): DataSet=DataSetElse: DataSet= Dataset.decode ('Utf-8')            ifisinstance (everyfilepath,unicode): Env.workspace= everyfilepath+"\\"+DataSet Dspath= everyfilepath+"\\"+DataSetElse: Env.workspace= everyfilepath+"\\"+dataset.encode ('gb2312') Dspath= everyfilepath+"\\"+dataset.encode ('gb2312') Fclist= arcpy. Listfeatureclasses ("")            ifFclist andLen (fclist) >0: forFcinchfclist:#If FC is Unicode then do not change, otherwise Utf-8 FC encoding is decoded to Unicode                    ifisinstance (fc,unicode): FC=FCElse: FC= Fc.decode ('Utf-8')                    ifisinstance (dspath,unicode): Fcfullpath= dspath+"\\"+FCElse: Fcfullpath= dspath+"\\"+fc.encode ('gb2312') Randomviewname= fc+"View"+str (Random.randint (1,100000) arcpy. Maketableview_management (fc,randomviewname) Count=0 Count=Int (arcpy. Getcount_management (Randomviewname). GetOutput (0))ifCount = =0:arcpy. Delete_management (Fcfullpath)Print "Delete"+fcfullpath+"succeed at"+time.strftime ("%y-%m-%d%x", Time.localtime ())Else:    Print "Dir not Exist"Print " Done"                                                                                                                                                                                                                                                                                                            
View Code

Delete a GIS database empty layer (Gdb,mdb,shape)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.