Public Function FindLayer(Puid As UID, LayerName As String) As ILayer Dim pApp As IApplication Set pApp = New AppRef Dim pMxDoc As IMxDocument Dim pMap As IMap Set pMxDoc = pApp.Document Set pMap = pMxDoc.FocusMap Dim theLayer As ILayer Dim pEnumLayer As IEnumLayer Set pEnumLayer = pMap.Layers(Puid, False) pEnumLayer.Reset Set theLayer = pEnumLayer.Next Do While Not theLayer Is Nothing 'Only search the selectable layers 'MsgBox pFeatureLayer.Name If theLayer.name = LayerName Then Set FindLayer = theLayer End If Set theLayer = pEnumLayer.Next Loop End Function Public Function OpenRasterDataset(sDir As String, sRasterDs As String) As IRasterDataset ' Open raster dataset in a workspace On Error GoTo er Dim pWsFact As IWorkspaceFactory Dim pWS As IRasterWorkspace Set pWsFact = New RasterWorkspaceFactory Set pWS = pWsFact.OpenFromFile(sDir, 0) Set OpenRasterDataset = pWS.OpenRasterDataset(sRasterDs) Set pWsFact = Nothing Set pWS = Nothing Exit Function er: MsgBox "Open Raster Dataset Error :" + err.Description End Function Public Function MakePermanentRaster(pRaster As IRaster, sOutputPath As String, sOutputName As String) As Boolean On Error GoTo erh If sOutputPath = "" Or sOutputName = "" Then MakePermanentRaster = False Exit Function End If Dim iPos As Integer iPos = InStr(sOutputName, ".") Dim sExt As String If iPos > 0 Then sExt = Mid(sOutputName, iPos + 1) Else sExt = "" End If Dim sFormat As String Select Case sExt Case "" sFormat = "GRID" Case "tif" sFormat = "TIFF" Case "img" sFormat = "IMAGINE Image" Case Else MsgBox "Make Permanent Raster: Unsupported file extension" MakePermanentRaster = False Exit Function End Select Dim pWS As IWorkspace Set pWS = SetRasterWorkspace(sOutputPath) Dim pBandC As IRasterBandCollection Set pBandC = pRaster pBandC.SaveAs sOutputName, pWS, sFormat MakePermanentRaster = True Exit Function erh: MsgBox "Make Permanent Raster:" & err.Description MakePermanentRaster = False End Function Public Function SetRasterWorkspace(sPath As String) As IWorkspace ' Given a pathname, returns the raster workspace object for that path On Error GoTo ErrorSetWorkspace Dim pWSF As IWorkspaceFactory Set pWSF = New RasterWorkspaceFactory If pWSF.IsWorkspace(sPath) Then Set SetRasterWorkspace = pWSF.OpenFromFile(sPath, 0) Set pWSF = Nothing End If Exit Function ErrorSetWorkspace: Set SetRasterWorkspace = Nothing End Function