>  기사  >  데이터 베이스  >  怎么对ArcSDE数据库的要素类进行批量重建空间索引

怎么对ArcSDE数据库的要素类进行批量重建空间索引

WBOY
WBOY원래의
2016-06-07 15:47:521371검색

在我们遇到很多有关于性能的问题,我们一般建议用户重新常见空间索引,那么如果用户一个库里面有几十个甚至上百个空间索引,那么该怎么处理呢? ArcGIS10.1版本 RebuildIndexes:(这个功能只有ArcGIS10.1才有的) 这个功能主要是对用户进行大范围数据编辑,

在我们遇到很多有关于性能的问题,我们一般建议用户重新常见空间索引,那么如果用户一个库里面有几十个甚至上百个空间索引,那么该怎么处理呢?

ArcGIS10.1版本


RebuildIndexes:(这个功能只有ArcGIS10.1才有的)
       这个功能主要是对用户进行大范围数据编辑,在原有数据基础上做大量的数据加载或者数据删除后,为了提高数据性能,进行的操作。其实听到这里有点老生常谈,我们原来的方法也是一个图层一个图层的进行重建索引,但是这个功能可以批量的重建索引,而且及支持属性索引也支持空间索引,支持系统表以及版本的增量表的重建索引,比较方便。

怎么对ArcSDE数据库的要素类进行批量重建空间索引

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_40

sdelayer -o normal_io -l victoria,parcels -u av -p mo -i esri_40

When 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 OFF
pause "按任意键开始"
sdelayer  -o load_only_io -l quxian,shape -i 5151 -s 192.168.220.165 -u sde -p sde
echo "图层quxian已经删除了空间索引"
sdelayer  -o normal_io -l quxian,shape -i 5151 -s 192.168.220.165 -u sde -p sde
echo "图层quxian已经创建了空间索引"

...

sdelayer  -o load_only_io -l quxian1,shape -i 5151 -s 192.168.220.165 -u sde -p sde
echo "图层quxian1已经删除了空间索引"
sdelayer  -o normal_io -l quxian1,shape -i 5151 -s 192.168.220.165 -u sde -p sde
echo "图层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)
执行过程中,我们可以看到右边的信息框的执行过程。

 -------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------------

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.