怎么对ArcSDE数据库的要素类进行批量重建空间索引
来源:互联网 发布:如何降低wifi网络延迟 编辑:程序博客网 时间:2024/05/16 04:54
在我们遇到很多有关于性能的问题,我们一般建议用户重新常见空间索引,那么如果用户一个库里面有几十个甚至上百个空间索引,那么该怎么处理呢?
ArcGIS10.1版本
RebuildIndexes:(这个功能只有ArcGIS10.1才有的)
这个功能主要是对用户进行大范围数据编辑,在原有数据基础上做大量的数据加载或者数据删除后,为了提高数据性能,进行的操作。其实听到这里有点老生常谈,我们原来的方法也是一个图层一个图层的进行重建索引,但是这个功能可以批量的重建索引,而且及支持属性索引也支持空间索引,支持系统表以及版本的增量表的重建索引,比较方便。
ArcGIS10之前的版本
但是对ArcGIS10以及之前的版本并没有批量重建索引的办法,我们只能另辟蹊径了。
1:使用sde命令行的方法
我们可以使用sde命令,load_only_io和normal_io进行切换来进行空间索引的重建,具体请看帮助。
Switch between load only and normal I/O modes.To modify a feature class's input/output mode, use the load_only_io and normal_io operations.You must be the owner of the feature class to change it from normal I/O to load-only I/O mode.It is recommended that you do not place a versioned feature class that uses binary storage in load only I/O mode because, when you switch back to normal I/O mode, the spatial index will be calculated on a versioned representation of the features. This representation may not match what is stored in the nonversioned f table to which the index gets applied. If this is the case, an error is returned.When the sdelayer command is used to create a layer (i.e., if the register or add operations are used), the resultant feature class is automatically in normal I/O mode. The load-only I/O mode is provided to make bulk data loading processes more efficient. Use load-only mode when performing large inserts to avoid the continuous update of the feature class's indexes.For feature classes that use a spatial grid index (SDEBINARY, SDELOB, WKB_GEOMETRY, or feature classes in DB2), if the grid fields are updated while the feature class is in load-only I/O mode, the spatial index is rebuilt with the new grid sizes when you reset the feature class to normal I/O mode. While rebuilding the spatial index table, the feature class is inaccessible to other users. Note: You can change the grid sizes while the feature class is in normal or load-only I/O mode. If you reset spatial indexes while the feature class is in normal I/O mode, the indexes on the spatial index table are dropped while the spatial index is being re-created.. When the feature class is in normal I/O mode, the envelope is automatically updated whenever a feature that extends the current envelope is added. The envelope is not updated while the feature class is in load-only I/O mode but is recalculated to the full extent when the feature class is reset to normal I/O mode.These examples show the parcels feature class being moved into load only mode then back to normal I/O mode.sdelayer -o load_only_io -l victoria,parcels -u av -p mo -i esri_40sdelayer -o normal_io -l victoria,parcels -u av -p mo -i esri_40When the feature class is returned to normal I/O mode, the spatial index table and database indexes are rebuilt. If the operation does not complete successfully for any reason, the feature class is left in load-only I/O mode.When a feature class is in load-only I/O mode, the unique index is removed from the feature class's spatial column. When the index is absent, it is possible to enter nonunique values into the spatial column with an application not created with the ArcSDE C- or Java application programming interface (API). Therefore, no applications besides ArcSDE or applications created with the ArcSDE C- or Java API should ever update the spatial column. Database administrators should be aware of the increased vulnerability of the spatial column when the feature class is in load-only I/O mode.我知道很多朋友肯定没有认真看上面的英文解释,但是没有关系,大家只需要知道,如果我们使用load_only_io模式,就是删除空间索引,我们使用normal_io模式就是创建空间索引就可以了。
那么知道了这两个模式,我们在对该模式做一个延伸介绍
注意:一般情况下,如果我们业务有变更的情况,比如我们插入一条记录,如果是使用ArcGIS客户端或者相关API进行操作,除了我们新添加一条记录外,我们还同步的对空间索引进行更新,但是如果我们业务上有批量更新的情况,那么我们除了变更数据表,而且我们还要同步的批量变更空间索引信息,这样对性能会有一些影响。那么我们就可以在批量变更之前,将数据切换到load_only_io模式,然后进行批量变更,等变更业务彻底完成之后,再切换到normal_io模式,以达到重建索引的目的。
那么对数据量比较多的要素类,我们可以使用sde命令编写批处理文件来对数据进行批量创建空间索引
@echo OFFpause "按任意键开始"sdelayer -o load_only_io -l quxian,shape -i 5151 -s 192.168.220.165 -u sde -p sdeecho "图层quxian已经删除了空间索引"sdelayer -o normal_io -l quxian,shape -i 5151 -s 192.168.220.165 -u sde -p sdeecho "图层quxian已经创建了空间索引"...sdelayer -o load_only_io -l quxian1,shape -i 5151 -s 192.168.220.165 -u sde -p sdeecho "图层quxian1已经删除了空间索引"sdelayer -o normal_io -l quxian1,shape -i 5151 -s 192.168.220.165 -u sde -p sdeecho "图层quxian1已经创建了空间索引"pause "按任意键结束"将以上数据保存为.bat文件,用的时候直接运行即可。
2:使用python脚本重建索引
如果大家留心会发现一个问题,虽然上面使用sde命令可以对要素类进行批量重建索引,但是它仍然需要用户指定特定的要素类名称,那么如果及时个甚至上百个要素类,对用户来说仍然是一个梦魇,那么我们使用python脚本就可以很轻松的实现这个功能。
我们使用Python脚本可以对某个SDE连接下的数据集或者要素类进行遍历,然后对遍历的要素类使用GP工具,该GP工具可以删除和重建空间索引,就是这么简单
from arcpy import *env.workspace=r'Database Connections\Connection to 192.168.100.111.sde' for dataset in ListDatasets(): for fc in ListFeatureClasses("","ALL",dataset): RemoveSpatialIndex_management(fc) AddSpatialIndex_management(fc)执行过程中,我们可以看到右边的信息框的执行过程。
-------------------------------------------------------------------------------------------------------
版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!
-------------------------------------------------------------------------------------------------------
- 怎么对ArcSDE数据库的要素类进行批量重建空间索引
- ArcSDE数据库的要素类批量重建空间索引
- 怎么对ArcGIS for Server发布服务的要素类进行操作(字段增删、索引重建等)
- 怎么对ArcGIS for Server发布服务的要素类进行操作(字段增删、索引重建等)
- 使用存储过程批量查询ArcSDE要素类及索引的存储大小
- 如何进行批量索引重建?
- 怎么提高基于ArcSDE存储的要素类大数据量要素选择的性能
- ArcSDE for Oracle怎么恢复误删除的要素类和要素
- Sql server 日记 (自动对数据库中的索引进行重建)
- 查询Oracle数据库存储的要素类、空间索引、属性索引大小
- ArcSDE创建空间数据存储类型为ST_Geometry的要素类
- ArcSDE创建空间数据存储类型为ST_Geometry的要素类
- Oracle如何批量重建数据库索引
- ArcSDE空间索引
- ArcSDE空间索引
- ArcSDE Java SDK获得要素类的要素数量FeatureCount
- Python程序实现批量创建/重建空间索引
- 如何对ArcSDE空间网格大小进行优化?
- 高效程序员的40个好习惯和行为方式
- 正则表达式,30分钟教程
- QTP_QTP论坛
- POJ1050
- Richedit中插入图片BMP(BMP,文件),GIF(文件)
- 怎么对ArcSDE数据库的要素类进行批量重建空间索引
- Python连接MySQLdb的mach-o, but wrong architecture错误解决
- java解析xml文件读取本地dtd或者忽略dtd
- 使用yum下载而不安装rpm包
- 安装Windows7和Ubuntu双系统并使用Windows引导
- 如何在Android真机上检测是否有Google Map add-on
- JAVA WEB部分总结
- Excel文件导入到SQL,文本、数字丢失,变成NULL的处理
- 反连接的实验