Select to view content in your preferred language

Create a raster from subset of bands

703
1
Jump to solution
07-25-2018 11:03 PM
ModyBuchbinder
Esri Regular Contributor

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

0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor

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‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

0 Kudos
1 Reply
DuncanHornby
MVP Notable Contributor

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‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos