Hello all
I have a multi band raster (9 bands) and I need to create a 3 band raster from bands 1,3,4 in ArcObjects.
The way I do it in ArcMap is the MakeRasterLayer with the 3 needed bands and then copy raster it to a new name.
I cannot do the MakeRasterLayer in ArcObjects and retrieve the results.
The commands works successfully but I cannot get the results.
Here is my code:
ESRI.ArcGIS.DataManagementTools.MakeRasterLayer MakeRasterTool = new ESRI.ArcGIS.DataManagementTools.MakeRasterLayer();
MakeRasterTool.in_raster = @"D:\Rasters1\MultiBand.TIF";
MakeRasterTool.out_rasterlayer = "Three";
MakeRasterTool.band_index = "1,3,4";
result = GP.Execute(MakeRasterTool, null) as ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult;
ESRI.ArcGIS.Geoprocessing.IGPUtilities gpUtils = new ESRI.ArcGIS.Geoprocessing.GPUtilities();
IRaster RD = gpUtils.DecodeRaster(result.GetOutput(0));
I tried DecodeRasterLayer too with the same results.
Should I opened somehow the raster "Three"?
Thanks
Solved! Go to Solution.
The following VBA worked for me:
Public Sub Test()
Dim pGP As IGeoProcessor2
Set pGP = New GeoProcessor
pGP.OverwriteOutput = True
pGP.AddOutputsToMap = False
Dim pVA As IVariantArray
Set pVA = New VarArray
With pVA
.Add "Multispectral_L5151038_03820110324_MTL" ' Layer in map but could be full path
.Add "myRaster"
.Add "#"
.Add "#"
.Add "1;2;3" ' Note semicolon separated
End With
Dim pGR As IGeoProcessorResult2
Set pGR = pGP.Execute("MakeRasterLayer_management", pVA, Nothing)
If pGR.Status = esriJobSucceeded Then
With pVA
.RemoveAll
.Add "myRaster"
.Add "C:\scratch\aaa.tif"
End With
pGP.AddOutputsToMap = True
Set pGR = pGP.Execute("CopyRaster_management", pVA, Nothing)
End If
End Sub
The following VBA worked for me:
Public Sub Test()
Dim pGP As IGeoProcessor2
Set pGP = New GeoProcessor
pGP.OverwriteOutput = True
pGP.AddOutputsToMap = False
Dim pVA As IVariantArray
Set pVA = New VarArray
With pVA
.Add "Multispectral_L5151038_03820110324_MTL" ' Layer in map but could be full path
.Add "myRaster"
.Add "#"
.Add "#"
.Add "1;2;3" ' Note semicolon separated
End With
Dim pGR As IGeoProcessorResult2
Set pGR = pGP.Execute("MakeRasterLayer_management", pVA, Nothing)
If pGR.Status = esriJobSucceeded Then
With pVA
.RemoveAll
.Add "myRaster"
.Add "C:\scratch\aaa.tif"
End With
pGP.AddOutputsToMap = True
Set pGR = pGP.Execute("CopyRaster_management", pVA, Nothing)
End If
End Sub