操作方法

操作方法:使用 Python 从 ArcMap 中的地理数据库中删除地理处理历史记录

Last Published: August 17, 2021

摘要

地理处理工具会在地理数据库中添加有关其执行情况的元数据。 元数据包括工具名称、其位置以及启用地理处理记录时使用的参数。 GIS 管理员和管理者有时需要从要素类或工作空间元数据中删除地理处理历史记录。

以下脚本描述了如何使用 Python 脚本实现此目标以及从企业级地理数据库工作空间中移除地理处理历史记录的工作流。

过程

从要素类中移除地理处理历史记录

下方提供的说明描述了如何使用 Python 脚本实现此目标。 以下脚本为地理数据库中的所有要素类(包括存储在要素数据集中的要素类)自动执行此过程。

: 在 32 位 Python 版本中执行该过程。

更新变量后运行包含的 Python 脚本:

import arcpy import os, string ''' 运行脚本之前更新以下五个变量。''' version = "10.5" myWorkspace = r"C:\XML_out\dbinstance_testgdb.sde" gp_history_xslt = r"C:\Program Files (x86)\ArcGIS\Desktop{}\Metadata\Stylesheets\gpTools\remove geoprocessing history.xslt".format(version) output_dir = r"C:\XML_out" db_type = "SQL" #如果您的 db 具有空间视图,请将此值设置为 "SQL" 或 "Oracle"。 否则,可以将其设置为 ""。 def RemoveHistory(myWorkspace, gp_history_xslt, output_dir): ##移除要素数据集存储的要素类和文件地理数据库中的要素类的 GP 历史记录。     arcpy.env.workspace = myWorkspace     for fds in arcpy.ListDatasets('','feature') + ['']:         for fc in arcpy.ListFeatureClasses('','',fds):             data_path = os.path.join(myWorkspace, fds, fc)             if isNotSpatialView(myWorkspace, fc):                 removeAll(data_path, fc, gp_history_xslt, output_dir) def isNotSpatialView(myWorkspace, fc): ##确定项目是否为空间视图,如果是则为 listFcsInGDB() 返回 True        if db_type <> "":         desc = arcpy.Describe(fc)         fcName = desc.name         #Connect to the GDB         egdb_conn = arcpy.ArcSDESQLExecute(myWorkspace)         #Execute SQL against the view table for the specified RDBMS         if db_type == "SQL":             db, schema, tableName = fcName.split(".")             sql = r"IF EXISTS(select * FROM sys.views where name = '{0}') SELECT 1 ELSE SELECT 0".format(tableName)         elif db_type == "Oracle":             schema, tableName = fcName.split(".")             sql = r"SELECT count(*) from dual where exists (select * from user_views where view_name = '{0}')".format(tableName)             egdb_return = egdb_conn.execute(sql)             if egdb_return == 0:                 return True             else:                 return False         else: return True     else: return True def removeAll(data_path, feature, gp_history_xslt, output_dir): ##从要素类移除所有 GP 历史记录元数据。     arcpy.ClearWorkspaceCache_management()     name_xml = os.path.join(output_dir, str(feature)) + ".xml"     arcpy.XSLTransform_conversion(data_path, gp_history_xslt, name_xml)     print "Completed xml coversion on {0}".format(feature)     arcpy.MetadataImporter_conversion(name_xml, data_path)     print "Imported XML on {0}".format(feature) def makeDirectory(output_dir): ##创建目录以存储已转换元数据的 xml 表。 如果 ##目录已存在,则将在该处创建文件。     if not arcpy.Exists(output_dir):         os.mkdir(output_dir) if __name__ == "__main__":     makeDirectory(output_dir)     RemoveHistory(myWorkspace, gp_history_xslt, output_dir) print "Done Done"

从企业级地理数据库工作空间中移除地理处理历史记录

  1. 以地理数据库管理员身份连接到企业级地理数据库。
  2. 运行 XSLT 变换地理处理工具以从已移除地理处理历史记录的数据库中生成 .xml。
    • 源元数据:数据库连接
    • 输入 XSLT:Esri 工具位于
C:\Program Files (x86)\ArcGIS\Desktop10.5\Metadata\Stylesheets\gpTools\remove geoprocessing history.xslt
  • 输出文件:提供保存输出 .xml 文件的位置
已填充适当参数的“XSLT 变换”工具窗口
  1. 运行元数据导入程序地理处理工具以将输出 .xml 文件导入企业级地理数据库。
    • 源元数据:步骤 2 中生成的输出 .xml
    • 目标元数据:数据库连接
已填充适当参数的“元数据导入程序”工具窗口

文章 ID:000011751

从 ArcGIS 专家处获得帮助

联系技术支持部门

下载 Esri 支持应用程序

转至下载选项

相关信息

发现关于本主题的更多内容