You are here:
About setting a spatial index
Geodatabases and ArcSDE
Building a geodatabase
Defining the properties of a geodatabase
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.
This topic discusses how ArcGIS manages spatial indexes and what you should do to help maintain them.
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 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 and/or shorter than the features already in the feature class. To ensure 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 in 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 in 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 displays informing you that the spatial index grid size is invalid. If this happens, stop editing, bring up 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 will be 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 would like 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 you would get with the Recalculate button.
If you are using an R-tree spatial index or 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, you must specify a grid size or accept the default grid size of 1,000. Once a feature class is created, the grid size cannot be modified. Since the grid size is permanent, ArcGIS does not automatically recalculate its size at the end of certain operations as it does with file and ArcSDE geodatabases.
Keep in mind that the default size of 1,000 is specified in the units of the feature class's coordinate system. This means if your feature class is in a geographic coordinate system and you use the default, all features will be placed in a single grid cell. This will provide no benefits to performance.
If you suspect a poor grid size is causing slow performance, you can try reloading the data to a new feature class with an optimal grid size:
How to modify a spatial grid index
- Use the Calculate Default Spatial Grid Index geoprocessing tool to find a good grid size for the feature class. This tool outputs up to three optimal grid sizes. You will use the Default Spatial Grid Index 1 value in the next step.
- Create a new, empty feature class with the New Feature Class wizard. In the wizard, specify the same coordinate system and fields as in the feature class you're reloading (the wizard allows you to import these). When you get to the list of fields, click on the Shape field and, for the Grid 1 property, specify the new grid size. Proceed to complete the wizard.
- Use the Append geoprocessing tool to import all records from the source data to the new, empty feature class.
NOTE: Modifying the spatial index of a feature class in an ArcSDE geodatabase is available with ArcInfo and ArcEditor only.
These steps apply only to file geodatabases and feature classes in the following ArcSDE geodatabases and geometry storage types:
- ArcSDE for Oracle with ST_Geometry storage
- ArcSDE for Oracle with binary storage
- ArcSDE for SQL Server with binary storage
- ArcSDE for DB2
- In the Catalog tree, right-click the file or ArcSDE geodatabase feature class whose spatial index you want to modify. Note that you cannot modify the spatial index of a feature class in a personal geodatabase.
- Click Properties.
- Click the Indexes tab.
- To have ArcGIS set the grid size for you, click Recalculate.
- To set your own grid sizes, click Edit and enter one or more grid sizes, and click OK.
- Click OK to build the spatial index and close the Feature Class Properties dialog box.
- If you are unsure whether to recalculate the spatial index, you can always check to see if it's necessary. Click the Recalculate button to see how ArcGIS would update the grid sizes. If the new sizes are roughly the same as the current sizes, you do not need to update the index and can close the dialog box. If the sizes are different, you can click OK to rebuild the index with the new sizes.
- When you use the Recalculate button to update the spatial index of an ArcSDE feature class that is enabled for archiving, the spatial index on the archive table is automatically recalculated.
- When you use the Edit button to alter the spatial index of the feature class by providing specific grid values, if you want to also recalculate the spatial index on the archive table, you must use the ArcSDE sdelayer command. Consult the ArcSDE Administration Command Reference for details.
- Building a new spatial index for an ArcSDE feature class is a server-intensive operation—it should not be done on large feature classes when a large number of users are logged in to the server.
- If this functionality is inactive, it is likely you are using a geometry storage type that does not use spatial grid indexes.