怎么对ArcSDE数据库的要素类进行批量重建空间索引
在我们遇到很多有关于性能的问题,我们一般建议用户重新常见空间索引,那么如果用户一个库里面有几十个甚至上百个空间索引,那么该怎么处理呢? ArcGIS10.1版本 RebuildIndexes:(这个功能只有ArcGIS10.1才有的) 这个功能主要是对用户进行大范围数据编辑,
在我们遇到很多有关于性能的问题,我们一般建议用户重新常见空间索引,那么如果用户一个库里面有几十个甚至上百个空间索引,那么该怎么处理呢?
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_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.
那么知道了这两个模式,我们在对该模式做一个延伸介绍
注意:一般情况下,如果我们业务有变更的情况,比如我们插入一条记录,如果是使用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 "按任意键结束"
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)
-------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

As a world-renowned sports brand, Nike's shoes have attracted much attention. However, there are also a large number of counterfeit products on the market, including fake Nike shoe boxes. Distinguishing genuine shoe boxes from fake ones is crucial to protecting the rights and interests of consumers. This article will provide you with some simple and effective methods to help you distinguish between real and fake shoe boxes. 1: Outer packaging title By observing the outer packaging of Nike shoe boxes, you can find many subtle differences. Genuine Nike shoe boxes usually have high-quality paper materials that are smooth to the touch and have no obvious pungent smell. The fonts and logos on authentic shoe boxes are usually clear and detailed, and there are no blurs or color inconsistencies. 2: LOGO hot stamping title. The LOGO on Nike shoe boxes is usually hot stamping. The hot stamping part on the genuine shoe box will show

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

Use the DataAccessObjects (DAO) library in C++ to connect and operate the database, including establishing database connections, executing SQL queries, inserting new records and updating existing records. The specific steps are: 1. Include necessary library statements; 2. Open the database file; 3. Create a Recordset object to execute SQL queries or manipulate data; 4. Traverse the results or update records according to specific needs.
