ArcGIS for Desktop

  • Documentation
  • Pricing
  • Support

  • My Profile
  • Help
  • Sign Out
ArcGIS for Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS for Desktop

A complete professional GIS

ArcGIS for Server

GIS in your enterprise

ArcGIS for Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Pricing
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

Help

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • More...

Add Spatial Index

  • Summary
  • Usage
  • Syntax
  • Code sample
  • Environments
  • Licensing information

Summary

Adds a spatial index to a shapefile, file geodatabase, or ArcSDE 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 rebuild 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 ArcMap to use the 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.

  • The Spatial Grid 1, 2, and 3 parameters only apply to file geodatabases and certain ArcSDE geodatabase feature classes (those that use SQL Server binary storage, DB2, Oracle binary storage, or Oracle ST_Geometry).

    • If you are unfamiliar with setting spatial grid sizes or are unsure of what values to use, use the default values of 0,0,0. When default values are input, this tool will calculate an optimal grid size by examining all the input features.
    • Shapefiles and certain ArcSDE geodatabase feature classes (those that use Oracle Spatial, Informix, and PostgreSQL) do not use spatial indexes based on grid sizes; therefore, no spatial grid values need to be specified.
    • Personal geodatabase feature classes receive a spatial index grid size based on the spatial reference properties of the feature class. This index grid cannot be overridden, removed, or modified.
    • Spatial Grid 1 is the first, or lowest, grid level and has the smallest cell size. The cells are square, and the parameter value you enter is the length of one side. The unit of measure is that of the spatial reference of the feature class (for example, meters). Spatial Grid 2 should be at least three times as large as Spatial Grid 1, and Spatial Grid 3 at least three times as large as Spatial Grid 2.
  • If the Input Features already have a spatial index, Spatial Grid 1, 2, 3 displays the current spatial index grid values. If you enter 0,0,0 for the spatial grid parameters and execute this tool, the optimal grid size is calculated, and the index rebuilt. You can then view the calculated grid size by reopening this tool and reentering the feature class or layer (you would then click Cancel, since you do not need to rebuild the index). You can also use the Calculate Default Spatial Grid Index tool to calculate optimal grid sizes.

  • Adding a new spatial index to an ArcSDE 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 more information about spatial indexes, see the following:
    • Setting spatial indexes
    • Modifying indexes in shapefiles by adding a spatial index
    • Modifying indexes in shapefiles by updating a spatial index

Syntax

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

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

Feature Layer; Mosaic Layer; Raster Catalog Layer
spatial_grid_1
(Optional)

The Spatial Grid 1, 2, and 3 parameters apply only to file geodatabase and certain ArcSDE geodatabase feature classes. If you are unfamiliar with setting grid sizes, leave these options as 0,0,0, and ArcGIS will compute optimal sizes for you.

Double
spatial_grid_2
(Optional)

Cell size of the second spatial grid. Leave the size at 0 if you only want one grid. Otherwise, set the size to at least three times larger than Spatial Grid 1.

Double
spatial_grid_3
(Optional)

Cell size of the third spatial grid. Leave the size at 0 if you only want two grids. Otherwise, set the size to at least three times larger than Spatial Grid 2.

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 = "Database Connections/Connection to esoracle.sde"
arcpy.AddSpatialIndex_management("LPI.Land/LPI.PLSSFirstDivision", 500)
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 SDE feature class.

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

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

# Set local variables
in_features = "LPI.Land/LPI.PLSSFirstDivision"
spatial_grid_1 = "500"
spatial_grid_2 = ""
spatial_grid_3 = ""

# Execute AddSpatialIndex
arcpy.AddSpatialIndex_management(in_features, spatial_grid_1)

Environments

  • Current Workspace

Licensing information

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

Related topics

  • An overview of the Indexes toolset
  • Calculate Default Spatial Grid Index

ArcGIS for Desktop

  • Home
  • Documentation
  • Pricing
  • Support

ArcGIS Platform

  • ArcGIS Online
  • ArcGIS for Desktop
  • ArcGIS for Server
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Insiders Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
© Copyright 2016 Environmental Systems Research Institute, Inc. | Privacy | Legal