HOW TO

Calculate the recommended spatial index size for a feature class using ArcObjects

Last Published: April 26, 2020

Summary

Instructions provided describe how to use ArcObjects to calculate the recommended spatial index size for a feature class.

Procedure

 
  1. Start ArcCatalog.
  2. Create a new UIButtonControl; see the following technical article:
    How To: Create a new UIButtonControl
    Note:
    For more information on creating a UIControl, see the ArcGIS Desktop Help topic: 'Creating custom commands with VBA and UI Controls'
  3. Right-click the UIButtonControl and select View Source.
  4. Copy the code below into the UIButtonControl's click event.
     
    Code:
    
        Dim pGxApp As IGxApplication
        Dim pGxDataset As IGxDataset
        Dim pDataset As IDataset
        Dim pFClass As IFeatureClass
        Dim pFCursor As IFeatureCursor
        Dim pFeature As IFeature
        Dim dblTotal As Double
        Dim iFCount As Integer
        
        Set pGxApp = Application
        If pGxApp.SelectedObject Is Nothing Then
            MsgBox "Select FeatureClass"
            Exit Sub
        End If
        
        If Not TypeOf pGxApp.SelectedObject Is IGxDataset Then
            MsgBox "Select FeatureClass"
            Exit Sub
        End If
        
        Set pGxDataset = pGxApp.SelectedObject
        Set pDataset = pGxDataset.Dataset
        Set pFClass = pDataset
        
        If pFClass.ShapeType = esriGeometryPoint Then
            MsgBox "Select Line or Polygon FeatureClass"
            Exit Sub
        End If
        
        Set pFCursor = pFClass.Search(Nothing, False)
        Set pFeature = pFCursor.NextFeature
        dblTotal = 0
        iFCount = 1
        Do Until pFeature Is Nothing
            dblTotal = dblTotal + ((pFeature.Extent.Height + pFeature.Extent.Width) / 2)
            Set pFeature = pFCursor.NextFeature
            iFCount = iFCount + 1
        Loop
        
        MsgBox "Recommended Spatial Index: " & Round(((dblTotal / iFCount) * 3), 2)
    
  5. Select a feature class in ArcCatalog to calculate the recommended spatial index for and click the UIButtonControl.

Article ID:000006766

Software:
  • ArcMap 9 x
  • ArcMap 8 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic