Calculate Default Spatial Grid Index (Data Management)


Calculates a set of valid grid index values (spatial grid 1, 2, and 3) for the input features. Grid index values will be calculated even if the input features do not support spatial grid indexing.

Learn more about_spatial_indexes



CalculateDefaultGridIndex_management (in_features)
ParameterExplanationData Type

The features for which a valid spatial grid index will be calculated.

Feature Layer; Raster Catalog Layer

Code Sample

Calculate Default Grid Index Example (Python Window)

The following Python window script demonstrates how to use the CalculateDefaultGridIndex function in immediate mode.

import arcpy
from arcpy import env
env.workspace = "C:/data"
Calculate Default Grid Index Example 2 (Standalone Script)

The following standalone script uses the CalculateDefaultGridIndex function in a workflow to update the spatial index of a FC.

# Name:
# Description: Use Calculate Default Grid Index to update the spatial index of a FC
# Author: ESRI

# Import system modules 
import arcpy
from arcpy import env

# Set the workspace
env.workspace = "C:/data/data.gdb"

# Set local parameters
inFeatures = "river"

  # Get the grid sizes from the tool, this is a string with 3 semi-colon seperated values (typically something like "1500; 0; 0") 
  result = arcpy.CalculateDefaultGridIndex_management(inFeatures)
  indexGrids = []
  for count in range(0, result.outputCount):

  # First remove the existing grid index
    # if no index exists, RemoveSpaitalIndex will fail, but just keep going

  # Now add the indexes calculated by the tool
  arcpy.AddSpatialIndex_management(inFeatures, indexGrids)
except Exception, e:
  # If an error occurred, print line number and error message
  import traceback, sys
  tb = sys.exc_info()[2]
  print "Line %i" % tb.tb_lineno
  print e.args[0]


This tool does not use any geoprocessing environments

Related Topics

Licensing Information

ArcView: Yes
ArcEditor: Yes
ArcInfo: Yes