Calculate Default Spatial Grid Index (Data Management)

License Level:BasicStandardAdvanced

Summary

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

Usage

Syntax

CalculateDefaultGridIndex_management (in_features)
ParameterExplanationData Type
in_features

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"
arcpy.CalculateDefaultGridIndex_management("rivers.shp")
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: UpdateSI_Example.py
# 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"

try:
  # 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):
    indexGrids.append(result.getOutput(count))

  # First remove the existing grid index
  try:
    arcpy.RemoveSpatialIndex_management(inFeatures)
  except:
    # if no index exists, RemoveSpaitalIndex will fail, but just keep going
    pass

  # 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]

Environments

This tool does not use any geoprocessing environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
5/7/2015