Skip To Content

Add Spatial Index

Summary

Adds a spatial index to a shapefile, file geodatabase, or enterprise geodatabase feature class. Use this tool to either add a spatial index to a shapefile or feature class that does not already have one or to re-create an existing spatial index.

Usage

  • ArcGIS uses spatial indexes to quickly locate features in feature classes. Identifying a feature, selecting features by pointing or dragging a box, and panning and zooming all require a spatial index to locate features. The spatial index is defined by using a grid-based system that spans the extent of the features in a feature class, like a locator grid you might find on a common road map.

  • By default, ArcGIS creates and maintains a spatial index for geodatabase feature classes. For a geodatabase feature class to not have a spatial index, you must explicitly remove it using the Remove Spatial Index tool.

  • Adding a new spatial index to an enterprise geodatabase 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.

  • For SQL Server and Oracle feature classes, if the index already exists, the index will be dropped and recreated. The bounding box will also be recalculated for SQL Server feature classes.

Syntax

AddSpatialIndex_management (in_features, {spatial_grid_1}, {spatial_grid_2}, {spatial_grid_3})
ParameterExplanationData Type
in_features

Enterprise geodatabase feature class, file geodatabase feature class, or shapefile to which a spatial index is to be added or rebuilt.

Feature Layer; Mosaic Layer
spatial_grid_1
(Optional)

This parameter has been deprecated in ArcGIS Pro. Any value you enter is ignored.

Double
spatial_grid_2
(Optional)

This parameter has been deprecated in ArcGIS Pro. Any value you enter is ignored.

Double
spatial_grid_3
(Optional)

This parameter has been deprecated in ArcGIS Pro. Any value you enter is ignored.

Double

Code sample

AddSpatialIndex Example (Python Window)

The following Python Window script demonstrates how to use the AddSpatialIndex function in immediate mode.

import arcpy
import arcpy.env as ENV
ENV.workspace = "c:/Connections/Connection to esoracle.sde"
arcpy.AddSpatialIndex_management("LPI.Land/LPI.PLSSFirstDivision")
AddSpatialIndex Example 2 (stand-alone Python script)

The following Python script demonstrates how to use the AddSpatialIndex function in a stand-alone script.

# Name: AddSpatialIndex_Example2.py
# Description: Add a spatial index to a enterprise geodatabase feature class.

# Import system modules
import arcpy
import arcpy.env as ENV

# Set workspace
ENV.workspace = "c:/Connections/Connection to esoracle.sde"

# Execute AddSpatialIndex
arcpy.AddSpatialIndex_management(in_features)

Environments

Licensing information

  • ArcGIS Desktop Basic: Yes
  • ArcGIS Desktop Standard: Yes
  • ArcGIS Desktop Advanced: Yes

Related topics