删除GIS数据库空层(GDB,MDB,Shape)
来源:互联网 发布:对阿里的数据分析 编辑:程序博客网 时间:2024/06/07 01:07
批量删除GIS数据库空层。
# -*- coding: utf-8 -*-# ---------------------------------------------------------------------------# Merge.py# Created on: 2013-01-21 10:25:22.00000# (generated by WangLin_TJCH)# Description: # ---------------------------------------------------------------------------# Import arcpy moduleimport arcpyimport os.pathimport timeimport randomfrom arcpy import envFCDBDir = "D:\\aaa"dicAllFC={}fcall=[]GDBAllPath=[]if not isinstance(FCDBDir,unicode): FCDBDir = FCDBDir.decode('utf-8')#Get Dataset and FeatureClass,Store in dicAllFC,Key =fc value= dsif os.path.exists(FCDBDir): for dirpath,dirnames,filenames in os.walk(FCDBDir): # 遍历GDB文件夹 获取GDB for dirname in dirnames: if ".gdb" in dirname: gdbfilepath = os.path.join(dirpath,dirname) if not gdbfilepath in GDBAllPath: GDBAllPath.append(gdbfilepath) # 遍历MDB文件夹 获取MDB for filename in filenames: if os.path.splitext(filename)[1]=='.mdb': mdbfilepath = os.path.join(dirpath,filename) if not mdbfilepath in GDBAllPath: GDBAllPath.append(mdbfilepath) # 遍历Shp文件夹 获取Shape for filename in filenames: if os.path.splitext(filename)[1]=='.shp': shpfilepath = os.path.join(dirpath,filename) if not dirpath in GDBAllPath: GDBAllPath.append(dirpath) for everyfilepath in GDBAllPath: env.workspace = everyfilepath singlefclist = arcpy.ListFeatureClasses("","All") if singlefclist and len(singlefclist)>0: for singlefc in singlefclist: # 如果singlefc是unicode则不做改变,否则将utf-8的singlefc编码解码成unicode if not isinstance(singlefc,unicode): singlefc = singlefc.decode('utf-8') if isinstance(everyfilepath,unicode): fcfullpath = everyfilepath+"\\"+singlefc else: fcfullpath = everyfilepath+"\\"+singlefc.encode('gb2312') rows = arcpy.SearchCursor(fcfullpath, "", "", "","") count = 0 for featurecount in rows: count=count+1 if count ==0: arcpy.Delete_management(fcfullpath) print "Delete "+fcfullpath+" Succeed At"+time.strftime("%Y-%m-%d %X",time.localtime()) datasetlist = arcpy.ListDatasets("","Feature") for dataset in datasetlist: # 如果dataset是unicode则不做改变,否则将utf-8的dataset编码解码成unicode if isinstance(dataset,unicode): dataset = dataset else: dataset = dataset.decode('utf-8') if isinstance(everyfilepath,unicode): env.workspace = everyfilepath+"\\"+dataset dspath = everyfilepath+"\\"+dataset else: env.workspace = everyfilepath+"\\"+dataset.encode('gb2312') dspath = everyfilepath+"\\"+dataset.encode('gb2312') fclist = arcpy.ListFeatureClasses("") if fclist and len(fclist)>0: for fc in fclist: # 如果fc是unicode则不做改变,否则将utf-8的fc编码解码成unicode if isinstance(fc,unicode): fc = fc else: fc = fc.decode('utf-8') if isinstance(dspath,unicode): fcFullPath = dspath+"\\"+fc else: 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)) if count ==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"
0 0
- 删除GIS数据库空层(GDB,MDB,Shape)
- 删除GIS数据属性值空格(GDB,MDB,Shp)
- gis数据获取mdb、gdb、shapefile、数据
- pear mdb 数据库抽象层
- 批量裁剪GIS数据(包含GDB,MDB,Shp)
- 批量追加数据库(GDB,MDB,Shp)
- shape文件导入mdb文件
- AE中开发中,读取mdb或gdb中图层时,判断图层是否存在
- AE中开发中,读取mdb或gdb中图层时,判断图层是否存在
- 删除数据库中的空表
- 删除数据库中的空表
- Access 2003数据库规格以及空数据库的.mdb文件很大的情况
- 删除数据库中的拓扑层
- arcengine append shape追加到mdb
- 关于gis shape文件读写
- PEAR MDB 数据库抽象层 —— 一次编写—随处运行
- MDB,Oracle空间数据库访问及图层数据的处理
- 打造安全mdb数据库
- 模式识别_字符识别算法设计
- 解读2015之Spark篇:新生态系统的形成
- ViewPager中Fragment使用非onResume刷新(setUserVisibleHint)
- linux wc,uniq,cut用法总结
- _IO, _IOR, _IOW, _IOWR 宏的用法与解析
- 删除GIS数据库空层(GDB,MDB,Shape)
- 这就是记者的原生态
- OC基础:枚举类型
- 聊聊iterable,sequence和iterators
- OSG渲染树
- 无奈为何物?
- SAP 本地测试
- 一些常见svn图标的含义
- Linux内核调试方法总结