I am trying to open a dialog box which shows up only raster datasets so that I can select one and create Hill shade based on it. But I am facing a run time error for Dialog box when I click on the addin button. Could any one please help me out regarding this
Protected Overrides Sub OnClick()
'
' TODO: Sample code showing how to access button host
'
My.ArcMap.Application.CurrentTool = Nothing
Dim pMxDoc As IMxDocument = My.ArcMap.Document
Dim pMap As IMap = pMxDoc.FocusMap
Dim bObjectSelected As Boolean
Dim pGxDialog As IGxDialog = New GxDialog
'only show raster datasets
Dim pRasterFilter As IGxObjectFilter = New GxFilterRasterDatasets
'Layers and document declaration
Dim pGxObjects As IEnumGxObject = Nothing
Dim pGxDataset As IGxDataset
Dim pRasterLayer As IRasterLayer
Try
With pGxDialog
.AllowMultiSelect = False
.StartingLocation = "C:\Users\rxm160030\Downloads\Lab12\Data"
.Title = "Select Raster datasets to Add to Map"
.ObjectFilter = pRasterFilter
.DoModalOpen(My.ArcMap.Application.hWnd, pGxObjects)
End With
'If no file selected, exit
If bObjectSelected = Nothing Then Exit Sub
'Get first dataset
pGxDataset = pGxObjects.Next
'no dataset selected
If pGxDataset Is Nothing Then Exit Sub
'iterate through remaining datasets
Do Until pGxDataset Is Nothing
pRasterLayer = New RasterLayer
'assign dataset to rasterLayer
Dim pInputRaster As IRaster = pRasterLayer.Raster
'assign dataset name to rasterLayer
pRasterLayer.Name = pGxDataset.Dataset.Name
' Do something with the featureLayer
Dim choice1 As String = InputBox("Enter Azimuth")
Dim choice2 As String = InputBox("Enter Altitude")
Dim pSurfaceOp As ISurfaceOp = New RasterSurfaceOp
Dim pEnv As IRasterAnalysisEnvironment = pSurfaceOp
Dim pWSF As IWorkspaceFactory = New RasterWorkspaceFactory
Dim pWS As IWorkspace = pWSF.OpenFromFile("C:\Users\rxm160030\Downloads\Lab12\Data", 0)
pEnv.OutWorkspace = pWS
Dim pOutput As IGeoDataset = pSurfaceOp.HillShade(pInputRaster, choice1, choice2, True)
Dim pOutLayer As IRasterLayer = New RasterLayer
pOutLayer.CreateFromRaster(pOutput)
pOutLayer.Name = "HillShade"
pMap.AddLayer(pRasterLayer)
pMap.AddLayer(pOutLayer)
' Go to next dataset
pGxDataset = pGxObjects.Next
Loop
Catch ex As Exception
MsgBox("BtnAdd_Click Exception: " & ex.Message)
Finally
' Release ArcObjects objects
pGxObjects = Nothing
pRasterFilter = Nothing
pGxDialog = Nothing
pGxDataset = Nothing
pRasterLayer = Nothing
' Call garbage collection
GC.Collect()
GC.WaitForPendingFinalizers()
End Try
pMxDoc.ActiveView.PartialRefresh(esriViewGeography, Nothing, Nothing)
End Sub