Sub BatchRasterSpatialRef() 'get all rasters from a directory 'On Error GoTo error_h Dim pGxApp As IGxApplication Set pGxApp = Application Dim pGxObj As IGxObject Set pGxObj = pGxApp.SelectedObject If Not TypeOf pGxObj Is IGxFolder Then MsgBox "Please select a Folder", vbExclamation Exit Sub Else Dim pGxObjectCont As IGxObjectContainer Set pGxObjectCont = pGxObj 'Check to see if there are children Dim pEnumGxObj As IEnumGxObject Set pEnumGxObj = pGxObjectCont.Children If pEnumGxObj Is Nothing Then MsgBox "Nothing was found in the " & pGxObj.FullName & " Folder" Exit Sub End If 'need an array to to store rasters to convert to MrSids Dim myGxObjArr As IGxObjectArray Set myGxObjArr = New GxObjectArray Dim blnRaster As Boolean blnRaster = False Dim pGxObj1 As IGxObject Set pGxObj1 = pEnumGxObj.Next Do While Not pGxObj1 Is Nothing If pGxObj1.Category = "Raster Dataset" Then blnRaster = True myGxObjArr.Insert -1, pGxObj1 End If Set pGxObj1 = pEnumGxObj.Next Loop If Not blnRaster Then MsgBox "No Raster Datasets were found in the " & pGxObj.FullName & " Folder" Exit Sub Else Dim sDir As String sDir = pGxObj.FullName ' do the processing End If End If ' Get input/output workspace Dim pWsFact As IWorkspaceFactory Set pWsFact = New RasterWorkspaceFactory Dim pWs As IWorkspace Set pWs = pWsFact.OpenFromFile(sDir, 0) 'Get all the raster datasets of the input workspace Dim pEnumDs As IEnumDataset Set pEnumDs = pWs.Datasets(esriDTRasterDataset) If MsgBox("Set Spatial Reference for all rasters in folder" & vbNewLine & sDir, vbOKCancel, "Proceed?") = 1 Then ' ***** Set spatial references Call MultiSpatRef(pEnumDs) End If pGxApp.Refresh sDir GoTo cleanup error_h: MsgBox Err.Description cleanup: Set pWsFact = Nothing Set pWs = Nothing Set myGxObjArr = Nothing Set pEnumDs = Nothing Set pGxObj1 = Nothing Set pEnumGxObj = Nothing Set pGxObjectCont = Nothing Set pGxObj = Nothing Set pGxApp = Nothing End Sub Function SelectSpatRef() As ISpatialReference Set SelectSpatRef = Nothing Dim pGXDlg As IGxDialog Set pGXDlg = New GxDialog Dim pGxFilter As IGxObjectFilter Set pGxFilter = New GxFilterSpatialReferences Set pGXDlg.ObjectFilter = pGxFilter pGXDlg.Title = "Select Coordinate System" pGXDlg.StartingLocation = "Coordinate Systems" pGXDlg.AllowMultiSelect = False Dim pEnumGxObj As IEnumGxObject pGXDlg.DoModalOpen 0, pEnumGxObj Dim pGxPrj As IGxPrjFile pEnumGxObj.Reset Dim pGxObj As IGxObject Set pGxObj = pEnumGxObj.Next If Not pGxObj Is Nothing Then Set pGxPrj = pGxObj Set SelectSpatRef = pGxPrj.SpatialReference End If cleanup: Set pGXDlg = Nothing Set pGxFilter = Nothing Set pEnumGxObj = Nothing Set pGxPrj = Nothing Set pGxObj = Nothing End Function Sub MultiSpatRef(pEnumDs As IEnumDataset) Dim pSpatRef As ISpatialReference Set pSpatRef = SelectSpatRef If pSpatRef Is Nothing Then MsgBox "No Spatial Reference Chosen..." Exit Sub End If Dim pGDSE As IGeoDatasetSchemaEdit Dim pRasterDs As IRasterDataset Set pRasterDs = pEnumDs.Next Do While Not pRasterDs Is Nothing Set pGDSE = pRasterDs With pGDSE If .CanAlterSpatialReference Then .AlterSpatialReference pSpatRef End If End With Set pRasterDs = pEnumDs.Next Loop cleanup: Set pSpatRef = Nothing Set pRasterDs = Nothing Set pGDSE = Nothing End Sub