在我們遇到很多有關(guān)于性能的問題,我們一般建議用戶重新常見空間索引,那么如果用戶一個(gè)庫里面有幾十個(gè)甚至上百個(gè)空間索引,那么該怎么處理呢? ArcGIS10.1版本 RebuildIndexes:(這個(gè)功能只有ArcGIS10.1才有的) 這個(gè)功能主要是對用戶進(jìn)行大范圍數(shù)據(jù)編輯,
在我們遇到很多有關(guān)于性能的問題,我們一般建議用戶重新常見空間索引,那么如果用戶一個(gè)庫里面有幾十個(gè)甚至上百個(gè)空間索引,那么該怎么處理呢?
ArcGIS10.1版本
RebuildIndexes:(這個(gè)功能只有ArcGIS10.1才有的)
這個(gè)功能主要是對用戶進(jìn)行大范圍數(shù)據(jù)編輯,在原有數(shù)據(jù)基礎(chǔ)上做大量的數(shù)據(jù)加載或者數(shù)據(jù)刪除后,為了提高數(shù)據(jù)性能,進(jìn)行的操作。其實(shí)聽到這里有點(diǎn)老生常談,我們原來的方法也是一個(gè)圖層一個(gè)圖層的進(jìn)行重建索引,但是這個(gè)功能可以批量的重建索引,而且及支持屬性索引也支持空間索引,支持系統(tǒng)表以及版本的增量表的重建索引,比較方便。
ArcGIS10之前的版本
但是對ArcGIS10以及之前的版本并沒有批量重建索引的辦法,我們只能另辟蹊徑了。
1:使用sde命令行的方法
我們可以使用sde命令,load_only_io和normal_io進(jìn)行切換來進(jìn)行空間索引的重建,具體請看幫助。
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.
那么知道了這兩個(gè)模式,我們在對該模式做一個(gè)延伸介紹
注意:一般情況下,如果我們業(yè)務(wù)有變更的情況,比如我們插入一條記錄,如果是使用ArcGIS客戶端或者相關(guān)API進(jìn)行操作,除了我們新添加一條記錄外,我們還同步的對空間索引進(jìn)行更新,但是如果我們業(yè)務(wù)上有批量更新的情況,那么我們除了變更數(shù)據(jù)表,而且我們還要同步的批量變更空間索引信息,這樣對性能會(huì)有一些影響。那么我們就可以在批量變更之前,將數(shù)據(jù)切換到load_only_io模式,然后進(jìn)行批量變更,等變更業(yè)務(wù)徹底完成之后,再切換到normal_io模式,以達(dá)到重建索引的目的。
那么對數(shù)據(jù)量比較多的要素類,我們可以使用sde命令編寫批處理文件來對數(shù)據(jù)進(jìn)行批量創(chuàng)建空間索引
@echo OFF pause "按任意鍵開始" sdelayer -o load_only_io -l quxian,shape -i 5151 -s 192.168.220.165 -u sde -p sde echo "圖層quxian已經(jīng)刪除了空間索引" sdelayer -o normal_io -l quxian,shape -i 5151 -s 192.168.220.165 -u sde -p sde echo "圖層quxian已經(jīng)創(chuàng)建了空間索引" ... sdelayer -o load_only_io -l quxian1,shape -i 5151 -s 192.168.220.165 -u sde -p sde echo "圖層quxian1已經(jīng)刪除了空間索引" sdelayer -o normal_io -l quxian1,shape -i 5151 -s 192.168.220.165 -u sde -p sde echo "圖層quxian1已經(jīng)創(chuàng)建了空間索引" pause "按任意鍵結(jié)束"
2:使用python腳本重建索引
如果大家留心會(huì)發(fā)現(xiàn)一個(gè)問題,雖然上面使用sde命令可以對要素類進(jìn)行批量重建索引,但是它仍然需要用戶指定特定的要素類名稱,那么如果及時(shí)個(gè)甚至上百個(gè)要素類,對用戶來說仍然是一個(gè)夢魘,那么我們使用python腳本就可以很輕松的實(shí)現(xiàn)這個(gè)功能。
我們使用Python腳本可以對某個(gè)SDE連接下的數(shù)據(jù)集或者要素類進(jìn)行遍歷,然后對遍歷的要素類使用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)
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com