Calculate Default Spatial Grid Index (Data Management)
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_indexesUsage
The grid index values will be returned as a message from the tool. The values can be viewed in the geoprocessing Results window, or the value can be assigned to a variable in scripting by accessing the tool execution result object..
-
The spatial grid index of the Input Features is not updated by this tool. File or SDE geodatabase feature class spatial grid indexes can be modified using the Add Spatial Index tool, or in the feature class property page under the Index tab.
-
The set of values returned by the tool can be used with the Add Spatial Index or Copy Features tools, or for the Output Spatial Grid environment settings.
-
The returned grid size is based on the spatial reference, average feature size, and number of features in the input features.
Syntax
Parameter | Explanation | Data Type |
in_features |
The features for which a valid spatial grid index will be calculated. | Feature Layer; Raster Catalog Layer |
Code Sample
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")
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]