ArcGIS删除SDE存储所有对象但保留Schema

其实该文章的主旨就是,有许多情况,需要对ArcSDE库里面所有的对象(要素类、表)的数据进行清空,但是并不删除该对象,也就是说相关的结构还是保留着。


1:使用Python脚本来实现

大家都知道,ArcToolbox提供了delete features这个GP工具,那么就使用Python脚本来使用该工具以达到相关目的。

首先,修改以下环境变量

  • logWorkspace = "C:/Temp" 
  • workspace = "C:/connections/LOCATOR_CONN/DATAOWNER.sde" 
  • dLogName = "Log_dataset_del.txt" 
  • fLogName = "Log_fc_del.txt" 
  • tLogName = "Log_table_del.txt" 
  • schema = "sde.DATAOWNER" 

 schema=DATAOWNER 大小写是敏感的,不同数据库的写法不一
• Oracle: DATAOWNER 
• SQL Server: db_name.DATAOWNER 
• PostgreSQL: db_name.DATAOWNER

import arcpy, os, string



def DelDatasets(logWorkspace,dLogName,workspace,schema):

    logfile = open(os.path.join(logWorkspace, dLogName), 'w')

    arcpy.env.workspace = workspace

    datasetList = arcpy.ListDatasets()

    for dataset in datasetList:

        if dataset.startswith(schema):
            
            arcpy.Delete_management(dataset)

            print ("Deleted Feature dataset {0}".format(dataset))

            logfile.write("Deleted Feature dataset {0}".format(dataset))

            logfile.write("\n")

    logfile.close()

    del logfile, datasetList
    

def DelFeatureClasses(logWorkspace,fLogName,workspace,schema):

    logfile = open(os.path.join(logWorkspace, fLogName), 'w')

    arcpy.env.workspace = workspace

    fcList = arcpy.ListFeatureClasses()

    for fc in fcList:

        if fc.startswith(schema):
           
            arcpy.Delete_management(fc)

            print ("Deleted feature class {0}".format(fc))

            logfile.write("Deleted feature class {0}".format(fc))

            logfile.write("\n")

    logfile.close()

    del logfile, fcList


def DelTables(logWorkspace,tLogName,workspace,schema):

    logfile = open(os.path.join(logWorkspace, tLogName), 'w')

    arcpy.env.workspace = workspace

    tableList = arcpy.ListTables()

    for table in tableList:

        if table.startswith(schema):           

            arcpy.Delete_management(table)

            print ("Deleted table {0}".format(table))

            logfile.write("Deleted table {0}".format(table))

            logfile.write("\n")

    logfile.close()

    del logfile, tableList


if __name__ == "__main__":
  

    logWorkspace = "C:/Temp"

    workspace = "C:/connections/LOCATOR_CONN/DATAOWNER.sde"

    dLogName = "Log_dataset_del.txt"

    fLogName = "Log_fc_del.txt"

    tLogName = "Log_table_del.txt"

    schema = "sde.DATAOWNER"

    DelDatasets(logWorkspace,dLogName,workspace,schema)

    DelFeatureClasses(logWorkspace,fLogName,workspace,schema)

    DelTables(logWorkspace,tLogName,workspace,schema)


通过上面的例子我们也可以延伸;

比如,批量删除按照某个属性过滤条件查询的功能。


相关问题:

如果用户的Workspace是PGDB或者FGDB,使用上面的方法修改相关参数值即可,但是如果是ArcSDE GDB,那么有个问题就需要用户留意一下,如果你的数据注册了版本,那么删除数据相关的信息就会在增量表中还有版本系统表中存储,这样无疑对ArcSDE库的性能影响很大。

ArcGIS版本介绍
http://wenku.baidu.com/view/7ad2ec7d27284b73f24250fe.html

所以,如果ArcSDE库里面的有注册版本的数据,需要留意这个问题。


2:其实也完全没有那么麻烦,我们完全可以直接将Workspace里面的所有Schema给导出来,然后再删除ArcSDE库里面所有数据,然后再导入相关Schema即可。

ArcGIS删除SDE存储所有对象但保留Schema_第1张图片

关于删除:

方案一:ArcCatalog可以批量删除

方案二:如果嫌麻烦,重新创建ArcSDE库来的更快。


所以说,ArcGIS有些时候有很多解决方法,而且猛一看功能是一样的,但是仔细想想,每个功能的设计都是针对不同的使用场景。

比如,光一个导入导出功能有这么几种:

1:ArcCatalog的Copy/Paste

2:ArcCatalog的Import/export

3:ArcCatalog的load data

4:Arcmap的Export(选中TOC的图层右键)

5:ArcSDE的sdeexport/sdeimport

6:ArcSDE的shp2sde/sde2shp

如果我们都能够举一反三,相互延伸,那么对学习的相关知识认识会是更加深刻。


 -------------------------------------------------------------------------------------------------------
版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!
-------------------------------------------------------------------------------------------------------

你可能感兴趣的:(ArcGIS删除SDE存储所有对象但保留Schema)