Home    |    Concepts   |   API   |   Samples
Concepts > Schema Objects > Layers
Spatial indexing

The spatial index is used to decrease the time it takes to locate features that match a spatial query.

Spatial indexes are implemented differently depending on the database management system (DBMS) used. The IBM Informix Spatial DataBlade module, the PostgreSQL implementation, and Oracle Spatial use an R-tree index to allow indexing of spatial data. SQL Server databases using spatial types use a type of b-tree index. DB2, Oracle databases using ST_Geometry or binary geometry storage, and SQL Server databases using binary geometry storage use a spatial grid index.

Spatial grid index

Spatial grid indexes define imaginary x/y grids for a feature class. There may be one, two, or three of these grid levels defined per feature class. The size of each grid in the feature class must be at least three times the previous grid size. Most feature classes need only one grid level, but more levels may be needed if the average sizes of the feature envelopes vary widely.

Users have the option to create sparse spatial index grids. Sparse grids populate the spatial index with information for only those grids that actually contain a portion of a feature. For example, if a spatial index is created on a river feature class, only those grids that the river crossed would be indexed for the river.

This could be more efficient for spatial queries, because grids that do not qualify as crossing the feature (in this case, rivers) will be eliminated from the query results during the primary filter process ArcSDE performs when executing spatial queries. Be aware that if third-party applications are used to perform envelope-on-envelope spatial queries, using a sparse index grid will affect query results.

If instead, a full grid is used for the rivers, the non-qualifying grids would still be eliminated, but they would not be eliminated until the secondary filter process.

Thus, with spatial grid indexing, users can:

  1. Calculate an adequate set of index grid values for a set of features:

    Users can calculate an adequate set of index grid values for a set of features by using their envelopes. In order to accomplish this, after creating the layer grid object, all shapes or envelopes should be applied to it, then the grid sizes should be retrieved, and finally the layer grid object should be freed. Please note that the API would deliberately not check to make sure a connection existed before operating.

    Also note that:

    1) If no valid envelopes are supplied, the API would return:

        grid_size1 = 1000000.0 / layerGrid->xyUnits
        grid_size2 = 1000000000.0 / layerGrid->xyUnits

    2) If only point features are supplied, the API would return:

        grid_size1 = 1000.0 / layerGrid->xyUnits
     

  2. Alter an existing layer so that an adequate set of index grid values are calculated and applied

    When an existing layer (of the types that use grid indexes) with actual data in it has either no index or a dubious index, an index grid can still be calculated. In order to accomplish this, SE_SPATIALINDEX_AUTOMATIC could be passed to SE_layerinfo_set_grid_sizes() and from there to SE_layer_alter() or SE_layer_create().

    SE_SPATIALINDEX_AUTOMATIC behaves as follows:

    For Oracle Spatial and Informix, it would be as if SE_SPATIALINDEX_RTREE had been entered.  For all other storage methods, if the layer is in normal IO mode, then if the layer has 0 features, it will cause the grid type to be be set to SE_SPATIALINDEX_NONE, and if more than 0 features, it will use the above code to calculate a set of grid sizes and set them.  If instead the layer is is load_only mode, then its grid type will be stored as SE_SPATIALINDEX_AUTOMATIC, and the previous logic will be applied when it is returned to normal IO mode.
     

  3. Customize maximum number of grids per layer (MAX_GRIDS_PER_FEAT) on a layer

    You can set the maximum number of grids for a layer using MAX_GRIDS_PER_FEAT. The default value of MAX_GRIDS_PER_FEAT is 1000.

    The SE_layerinfo_get_shape_types() and SE_layerinfo_set_shape_types() API functions can be used to modify the maximum number of grids for a layer.

    The following ArcSDE administration commands also support modifiable MAX_GRIDS_PER_FEAT:

    sdelayer: (sdelayer –o add and –o alter)  –F <max_grids_feat>
    sdeimport:  (sdeimport –o create) –F <max_grids_feat>
    shp2sde: (shp2sde –o create) –F <max_grids_feat>
    cov2sde: (cov2sde –o create)  –F <max_grids_feat>

    Please note that this option only applies to layers with grid indexes.
     

  4. Enable/Disable generation of sparse feature grids.

    By manipulating the SE_GENERATE_SPARSE_GRIDS_MASK flag on a layer, users can enable/disable generation of sparse feature grids on layers.

    The SE_layerinfo_has_sparse_grids() and SE_layerinfo_set_sparse_grids() API functions can be used to manipulate this flag.

    The following ArcSDE administration commands also support enabling/disabling sparse feature grids:

    sdelayer -o add and -o alter
    sdeimport -o create
    shp2sde -o create
    cov2sde -o create.

    For more details on administration commands, please refer to ArcSDE Administration Command reference.

R-tree index

There is no need to set grid values for R-tree indexes. However, the C API function SE_layerinfo_set_grid_sizes and Java function setGridSizes() are also used to specify the creation of an R-tree index. To create an R-tree index, pass -2.0 for the grid_size1 parameter.

Modified B-tree index
There is also no need to set grid values for the SQL Server spatial indexes, but the C API function SE_layerinfo_set_grid_sizes and Java function setGridSizes() are also used to specify the creation of a spatial index for the SQL Server spatial types. To create this index, pass -6.0 for the grid_size1 parameter.
feedback | privacy | legal