A quick tour of setting a spatial index
The spatial index is used to quickly locate features when you display, edit, or query data. Therefore, an appropriate spatial index is important, especially when you're working with large amounts of data.
Spatial indexes work differently depending on the data source. File and ArcSDE geodatabases in DB2, ArcSDE geodatabases in Oracle and SQL Server that use binary geometry storage, and ArcSDE geodatabases in Oracle that use ST_Geometry storage use a system of up to three grids as the spatial index. Personal geodatabases use a single grid. A grid is defined by a size, referred to as the grid size. This is the size of each cell in the grid, specified in the units of the feature class's coordinate system. Oracle Spatial, Informix, and PostgreSQL do not use grid sizes—they use an R-tree index. Similarly, with SQL Server spatial types, the spatial index does not use grids.
How ArcGIS maintains indexes in file and ArcSDE geodatabases
ArcGIS automatically rebuilds the spatial index at the end of certain operations in file and ArcSDE geodatabases to ensure that the index is optimal. The following explains how ArcGIS manages the spatial index:
- When you create an empty feature class with the New Feature Class wizard, a spatial index is created. If the feature class uses a spatial grid index, the index is created with grid sizes 0,0,0 and left in an unbuilt state. After loading data with the simple data loader in ArcCatalog or the Append tool, ArcGIS builds the spatial index as a final step of the loading process. It calculates grid sizes that are appropriate for the newly added features.
- If you import data from a personal geodatabase, shapefile, or coverage or import computer-aided drafting (CAD) or Smart Data Compression (SDC) data, a spatial index is automatically computed for the new feature class.
- When using the ArcCatalog Copy and Paste commands to copy a feature class from a personal to a file or ArcSDE geodatabase, the spatial index is automatically rebuilt. The spatial index is also rebuilt if you copy a feature class from Oracle Spatial, PostgreSQL, or Informix. If you copy a feature class from a file or an ArcSDE geodatabase that uses grid sizes (Oracle binary and ST_Geometry, SQL Server binary, or DB2) to another geodatabase that uses grid sizes, the index is copied along with the source data and not recomputed.
- When you use a geoprocessing tool that creates a feature class, the features in the new feature class are examined and a new spatial index is automatically computed.
- When you save edits to a file geodatabase feature class in ArcMap, ArcGIS analyzes the spatial index. If grid sizes are set to 0,0,0, it automatically rebuilds the index with an appropriate grid size given the features that have just been added. This does not occur in ArcSDE geodatabases.
- Compressed file geodatabase feature classes do not use the same type of spatial index used in uncompressed feature classes. When you compress a file geodatabase feature class, it is automatically reindexed. This index cannot be modified. When you uncompress the feature class, the same spatial index the feature class had before it was compressed is automatically reestablished.
When to update the index in file and ArcSDE geodatabases
Because ArcGIS maintains the spatial index in file and ArcSDE geodatabases, you seldom need to manually set or recalculate the index. Changing or recalculating the index is required only in the following rare situations:
- Manually recalculate the index after you have added a large number of features that differ in size from the features that are already in the feature class. This applies to adding features in edit sessions only. For example, you may have started an edit session and manually added a large number of line features or used the Object Loader to load them. Many of the features you've added are either considerably longer or shorter than the features already in the feature class. To ensure that the spatial index will work optimally with the new features, it should be updated. If the feature class uses a spatial grid index, after you have saved edits, update the index by accessing the Indexes tab on the Feature Class Properties dialog box and clicking the Recalculate button.
- If you are adding features to a file geodatabase feature class with grid sizes 0,0,0 and save edits, the index is automatically built for you. However, if you continue to add features in the same edit session, the index is not recalculated on subsequent saves, since grid sizes are no longer 0,0,0. Once you've finished adding features, click the Recalculate button on the Feature Class Properties dialog box to update the grid sizes. Keep in mind, though, that manually recalculating the index after adding features that are similar in size to the features already in the feature class will make little or no difference to the index.
- If you want to add large features to a feature class, you may need to delete the index before you can add the features. You will know this is the case if when adding features an error message appears informing you that the spatial index grid size is invalid. If this happens, stop editing, open the Feature Class Properties dialog box, and delete the spatial index. Restart the edit session and add the new features. Once you have finished adding the features, recalculate a new index.
This topic has so far mostly discussed using the default grid sizes calculated by ArcGIS for spatial grid indexes. In most circumstances, the default grid size is appropriate for fast spatial queries. However, depending on the characteristics of your data and how you access it, it may not be the optimal size. Setting your own grid sizes may result in better performance. Finding better grid sizes involves experimenting with different sizes and running performance tests each time to observe the effects. However, you may not be able to improve performance—the existing grid size may already be optimal.
If you manually entered grid sizes and want to revert to a size provided by ArcGIS, you can recalculate a new grid size at any time. Click the Recalculate button on the Index tab of the Feature Class Properties dialog box. ArcGIS can also calculate an appropriate grid size with the Calculate Default Spatial Grid Index geoprocessing tool, although this provides the same size that you get with the Recalculate button.
If you are using Microsoft SQL Server spatial type indexes, grids are not used, and therefore, there is no need to recalculate grids.
Spatial indexes in personal geodatabases
Whenever you create a feature class in a personal geodatabase, whether with the New Feature Class wizard, a geoprocessing tool, or any other method, the spatial index grid size will be calculated for you by the software and it cannot be modified. The calculated grid size is based on the horizon of the feature class coordinate system and will always be optimal.