English

How To: Copy an ArcSDE embedded raster catalog to a new user using ArcObjects

Summary

Note: 
The information in this article applies to ArcGIS versions 9.x only. Later versions of ArcGIS may contain different functionality, as well as different names and locations for menus, commands and geoprocessing tools.
Note: 
Support for Visual Basic for Applications (VBA) for ArcMap and ArcCatalog ended with the ArcGIS 10.2.2 release, and Esri has not included VBA compatibility setups since version 10.5. See: ArcGIS Desktop and VBA Moving Forward

Instructions provided describe how to copy and paste an ArcSDE embedded raster catalog to a new using ArcObjects.

Procedure

  1. Start ArcMap.
  2. Create a new UIButtonControl: 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'
  1. Right-click the UIButtonControl and select View Source.
  2. Copy this code into the UIButtonControl's click event. Modify the connection properties to reflect the settings of the database being connected to.
Dim pCat As IRasterCatalogTable
    Dim pws As IFeatureWorkspace
    Dim pRaster As IRaster
    Dim i As Integer
    
    Set pws = open_workspace("myserver", "5151", "", "user1", "user2")
    Set pCat = open_sde_rastercatalog(pws, "oldcat")
    For i = 0 To pCat.size - 1
        Set pRaster = pCat.RasterDataset(pCat.OID(i)).CreateDefaultRaster
        If i > 0 Then flag = True
        LoadToSDE pRaster, "myserver", "5151", "", "user2", "user2", "copycat"
    Next i
  1. Copy this code above the UIButtonControl's click event.
Dim flag As Boolean
  1. Copy this code below the UIButtonControl's click event.
Public Sub LoadToSDE(pRaster As IRasterProps, sServer As String, sInstance As String, _
                     sDB As String, sUser As String, sPasswd As String, sSDERaster As String)
  
    ' sDir: the directory where the input raster resides
    ' sInput: the name of input raster
    ' sServer,sInstance,sDB,sUser,sPasswd: ArcSDE connection info
    ' sSDERaster: the output ArcSDE raster dataset name
    Dim pSDEConn As IRasterSdeConnection2
    Dim pSDEStorage As IRasterSdeStorage2
    Dim pSDEOp As IRasterSdeServerOperation2
    Dim pRasterWsFact As IWorkspaceFactory
    Dim pRasterWs As IRasterWorkspace
    Dim pGeoDs As IGeoDataset
    Dim pCat As IRasterSdeCatalog
    
    ' Initialize RasterSDELoader
    Set pSDEConn = New RasterSdeLoader
    Set pCat = pSDEConn
    ' Make connection
    pSDEConn.ServerName = sServer
    pSDEConn.Instance = sInstance
    pSDEConn.Database = sDB
    pSDEConn.UserName = sUser
    pSDEConn.Password = sPasswd
    Set pSDEConn.Raster = pRaster
    pSDEConn.SdeRasterName = sSDERaster
    ' Set storage parameters
    Set pSDEStorage = pSDEConn
    pCat.CatalogName = sSDERaster
    pCat.RasterName = "image"
     
    ' Set spatialreference
    Set pSDEStorage.SpatialReference = pRaster.SpatialReference
    ' Set tilesize
    pSDEStorage.TileHeight = 128
    pSDEStorage.TileWidth = 128
    ' Pyramids option
    pSDEStorage.PyramidOption = esriRasterSdePyramidDonotBuild
    
    ' keyword
    pSDEStorage.Keyword = ""
    ' Start loading
    Set pSDEOp = pSDEConn
    If Not flag Then
       SDEOp.Create
    Else
       pSDEOp.Insert
    End If
    
    ' Cleanup
    Set pSDEConn = Nothing
    Set pSDEStorage = Nothing
    Set pSDEOp = Nothing
    Set pRasterWsFact = Nothing
    Set pRasterWs = Nothing
    Set pGeoDs = Nothing
  
End Sub
Function open_sde_rastercatalog(pws As IFeatureWorkspace, sTable As String) As IRasterCatalogTable
  
    ' Open a raster catalog table in an ArcSDE connection
    On Error Resume Next
    Dim pCatalogTable As IRasterCatalogTable
    Dim pTable As ITable
    
    Set pCatalogTable = New RasterCatalogTable
    If pws Is Nothing Then Exit Function
    ' Open table
    Set pTable = pws.OpenTable(sTable)
    ' Assign table to raster catalog
    Set pCatalogTable.Table = pTable
    ' Check if it is a raster catalog table
    If pCatalogTable.Table Is Nothing Then
       MsgBox sTable & " is not a raster catalog table"
       Exit Function
    End If
    
    pCatalogTable.Update
    Set open_sde_rastercatalog = pCatalogTable
    
    Set pCatalogTable = Nothing
    Set pTable = Nothing
    
End Function
Function open_workspace(sServer As String, sInstance As String, sDB As String, sUser As String, _
                        sPasswd As String) As IFeatureWorkspace
    
    ' Open a feature workspace using the input connection information
    Dim pFact As IWorkspaceFactory
    Dim pPropertySet As IPropertySet
    
    Set pFact = New SdeWorkspaceFactory
    Set pPropertySet = New PropertySet
    ' Populate connection property
    With pPropertySet
      .SetProperty "Server", sServer
      .SetProperty "Instance", sInstance
      .SetProperty "Database", sDB
      .SetProperty "user", sUser
      .SetProperty "password", sPasswd
      .SetProperty "version", "sde.DEFAULT"
    End With
    
    ' Open workspace
    Set open_workspace = pFact.Open(pPropertySet, 0)
    
    ' Clean up
    Set pFact = Nothing
    Set pPropertySet = Nothing
    
End Function