'Using the geoprocessing library Public Sub GeoprocessingBuffer() 'Create the geoprocessor Dim gp As IGeoProcessor2 = New GeoProcessor 'Create an IVariantArray to hold the parameter values. Dim parameters As IVariantArray = New VarArray 'Create the result object Dim result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2 Try ' Populate the variant array with parameter values. parameters.Add("C:\Docs\Lesley\GIS Programming\Slides\Week7\data\aoi_v.shp") parameters.Add("C:\Docs\Lesley\GIS Programming\Slides\Week7\data\aoi_v_buffer.shp") parameters.Add("1000 Meters") ' Execute the model tool by name. result = gp.Execute("Buffer_analysis", parameters, Nothing) ' If the job succeeded, retrieve the feature result. If result IsNot Nothing Then Dim outVal As IGPValue = result.GetOutput(0) parameters.RemoveAll() parameters.Add(outVal) parameters.Add("C:\Docs\Lesley\GIS Programming\Slides\Week7\data\aoi_v_buffer_copy.shp") gp.Execute("CopyFeatures", parameters, Nothing) End If Catch ex As Exception For Counter As Integer = 0 To gp.MessageCount - 1 Debug.Print("GP error: " & gp.GetMessage(Counter)) Next Finally gp = Nothing parameters = Nothing result = Nothing GC.WaitForPendingFinalizers() GC.Collect() End Try End Sub 'Geoprocessor managed assembly Public Sub GeoprocessorBuffer() 'Create the geoprocessor Dim GP As ESRI.ArcGIS.Geoprocessor.Geoprocessor = New ESRI.ArcGIS.Geoprocessor.Geoprocessor() ' Create the tool process object. Dim bufferTool As ESRI.ArcGIS.AnalysisTools.Buffer = New ESRI.ArcGIS.AnalysisTools.Buffer() ' Create the second tool process object Dim copyTool As ESRI.ArcGIS.DataManagementTools.CopyFeatures = New ESRI.ArcGIS.DataManagementTools.CopyFeatures() 'Create the result object Dim result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2 Try ' Set default workspace GP.SetEnvironmentValue("workspace", "C:\Docs\Lesley\GIS Programming\Slides\Week7\data") ' Populate the bufferTool with parameter values. bufferTool.in_features = "aoi_v.shp" bufferTool.out_feature_class = "aoi_v_buffer.shp" bufferTool.buffer_distance_or_field = "1000 Meters" ' Execute the model tool by name. result = GP.Execute(bufferTool, Nothing) ' If the job succeeded, retrieve the feature result. If result IsNot Nothing Then Dim outVal As IGPValue = result.GetOutput(0) copyTool.in_features = outVal copyTool.out_feature_class = "aoi_v_buffer_copy.shp" GP.Execute(copyTool, Nothing) End If Catch ex As Exception For Counter As Integer = 0 To gp.MessageCount - 1 Debug.Print("GP error: " & gp.GetMessage(Counter)) Next Finally gp = Nothing bufferTool = Nothing result = Nothing GC.WaitForPendingFinalizers() GC.Collect() End Try End Sub ' Informational function to dump the GP environment settings to the console Public Sub ListGPEnvironmentSettings() 'Create the geoprocessor Dim GP As ESRI.ArcGIS.Geoprocessor.Geoprocessor = New ESRI.ArcGIS.Geoprocessor.Geoprocessor() ' list all the Environments, hold the return of the method in an Enumeration Dim gpEnumEnv As IGpEnumList = GP.ListEnvironments("*") Dim strEnv As String = gpEnumEnv.Next While strEnv.Length > 0 Dim strVal As String = TryCast(GP.GetEnvironmentValue(strEnv), String) Debug.WriteLine(strEnv & ": " & strVal) strEnv = gpEnumEnv.Next End While End Sub Public Sub Geoanalyze() Dim pReclassOp As IReclassOp Dim pSliceRaster As IGeoDataset2 Dim pSourceRasterLayer As IRasterLayer Dim pSliceRasterLayer As IRasterLayer Dim pSourceRaster As IRaster Try ' Get current document Dim pMxDoc As IMxDocument = My.Document Dim pMap As IMap = pMxDoc.FocusMap ' Get raster layer from map pSourceRasterLayer = pMap.Layer(0) ' Get raster from rasterLaer pSourceRaster = pSourceRasterLayer.Raster pReclassOp = New RasterReclassOp ' execute slice Dim slices As Integer = 5 pSliceRaster = pReclassOp.Slice(pSourceRaster, esriGeoAnalysisSliceEnum.esriGeoAnalysisSliceEqualArea, slices) ' create new raster layer to add output to map pSliceRasterLayer = New RasterLayer pSliceRasterLayer.CreateFromRaster(pSliceRaster) pSliceRasterLayer.Name = CStr(slices) & " Slice layer" ' add output to map pMap.AddLayer(pSliceRasterLayer) Catch ex As Exception Debug.Print("Geoanalyze exception: " & ex.Message) Finally pSourceRaster = Nothing pSourceRasterLayer = Nothing pSliceRasterLayer = Nothing pSliceRaster = Nothing pReclassOp = Nothing GC.WaitForPendingFinalizers() GC.Collect() End Try End Sub