ArcGIS Python arcpy 批量创建SDE空间索引
2015-02-11 10:12
344 查看
1、 SDE连接文件建立 使用Desktop系统工具箱建立SDE连接文件,如果catalog已经直连到SDE可以省略此步骤。 2、 Python脚本导入Toolbox设置 脚本中使用变量为SDE表空间,在导入脚本过程中只需要指定这一个变量即可 (1) 新建工具箱 (2) 添加脚本 (3) 变量设置 输入名称,在数据类型下拉列表中选择“工作空间” (4) 脚本执行 在工具箱中双击建立的脚本,打开对话框,导航到SDE连接文件位置,按确定执行重建索引工作。 3、 脚本主要逻辑及脚本异常情况设置 脚本通过遍历SDE数据库下面的要素数据集以及要素类进行生成索引工作。生成索引过程中要确定要素不被其他程序占用,否则会出现独占锁情况出现,另外使用的建立空间索引为默认索引参数,如下所示0,0,0代表三级索引为默认索引arcpy.AddSpatialIndex_management(fc, 0, 0, 0)。
遍历完成后,获取该要素是否已经已有空间索引,已有索引先进行删除索引,然后进行重建,没有索引直接增加空间索引。
脚本如下:
# -*- coding: cp936 -*- import os import sys reload(sys) sys.setdefaultencoding( "utf-8" ) import arcpy # path = r"C:\Users\Administrator\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\连接到 localhost.sde" path = arcpy.GetParameter(0) arcpy.env.workspace = path #遍历SDE下面要素类# fcs = arcpy.ListFeatureClasses() for fc in fcs: try: desc = arcpy.Describe(fc) except: arcpy.AddError('Failed:' + fc + " Check this featureclass") #判断是否已经有空间索引 if (str(desc.hasSpatialIndex) == 'True'): try: arcpy.SetProgressorLabel("正在执行要素 " + fc + "...") #如果有空间索引先删除原有索引,然后重新创建 arcpy.RemoveSpatialIndex_management(fc) arcpy.AddMessage('Success:' + fc + ' Start Delete Spatial index') arcpy.AddSpatialIndex_management(fc, 0, 0, 0) arcpy.AddMessage('Success:' + fc + ' Create Spatial index Completed') except: arcpy.AddError('Failed:' + fc + " error") else: try: arcpy.SetProgressorLabel("正在执行要素 " + fc + "...") arcpy.AddSpatialIndex_management(fc, 0, 0, 0) arcpy.AddMessage('Success:' + fc + " had no Spatial index,just now Created Spatial Index ") except: arcpy.AddError('Failed:' + fc + " error") #遍历SDE下面的数据集 DSs = arcpy.ListDatasets() print(DSs) for ds in DSs: #遍历数据集下面的要素类 arcpy.env.workspace = str(path) + "\\" + ds print(arcpy.env.workspace) ff = arcpy.ListFeatureClasses() for fc in ff: try: desc = arcpy.Describe(fc) except: arcpy.AddError('Failed:' + fc + "Check this featureclass") if (str(desc.hasSpatialIndex) == 'True'): try: arcpy.SetProgressorLabel("正在执行要素 " + fc + "...") #如果有空间索引先删除原有索引,然后重新创建 arcpy.RemoveSpatialIndex_management(fc) arcpy.AddMessage('Success:' + fc + ' Start Delete Spatial index') arcpy.AddSpatialIndex_management(fc, 0, 0, 0) arcpy.AddMessage('Success:' + fc + ' Create Spatial index Completed') except: arcpy.AddError('Failed:' + fc + " error") else: try: arcpy.SetProgressorLabel("正在执行要素 " + fc + "...") arcpy.AddSpatialIndex_management(fc, 0, 0, 0) arcpy.AddMessage('Success:' + fc + " had no Spatial index,just now Created Spatial Index ") except: arcpy.AddError('Failed:' + fc + " error")
相关文章推荐
- 利用ArcGIS Python批量拼接裁剪遥感影像(arcpy batch processing)
- 利用ArcGIS Python批量拼接裁剪遥感影像(arcpy batch processing)
- Python实现批量执行ArcGIS版本的协调和提交
- ArcGIS Server Administrator API 编写python脚本(二)-----创建站点
- 使用Python创建.sd服务定义文件,实现脚本自动发布ArcGIS服务
- 在ArcGIS中创建Python工具(三)
- 在ArcGIS中创建Python工具(二)
- Python:在Linux下创建一个脚本并且自动修改权限,可以选择路径。批量生成脚本 。
- Python批量创建迅雷任务及创建多个文件
- ArcGIS Python批量插值、裁切
- Python 批量创建同文件名的特定后缀文件
- Python程序实现批量创建/重建空间索引
- arcgis for python (arcpy) 入门
- python使用循环实现批量创建文件夹示例
- python使用循环实现批量创建文件夹示例
- ArcGIS Python 批量定义投影
- Python实现批量执行ArcGIS版本的协调和提交 - ArcGIS技术研究 - 博客频道 - CSDN.NET
- ArcGIS Desktop python Add-in 创建一个插件
- [Python]批量创建目录
- 在ArcGIS中创建Python工具(一)