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.
Usage
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
CalculateDefaultGridIndex(in_features)
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
Calculate Default Grid Index Example (Python Window)
The following Python window script demonstrates how to use the CalculateDefaultGridIndex function in immediate mode.
import arcpy
arcpy.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
# Import system modules
import arcpy
# Set the workspace
arcpy.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, RemoveSpatialIndex will fail, but just keep going
pass
# Now add the indexes calculated by the tool
arcpy.AddSpatialIndex_management(inFeatures, indexGrids)
except Exception as err:
print(err.args[0])
Environments
This tool does not use any geoprocessing environments.
Licensing information
- Basic: Yes
- Standard: Yes
- Advanced: Yes