Multiply two or more rasters

Discussion created by meg36 on May 10, 2011
Latest reply on May 11, 2011 by meg36
Dear All,

I need to know how i can multiply more than 2 rasters. I have the code for times two rasters (see below) but when i declare a third inputdataset i get a compile error; 'wrong number of arguments or invalid property assignment'. I'm working in 9.3.

Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    Dim pMap As IMap
    Set pMap = pMxDoc.FocusMap

   Dim pWSFact As IWorkspaceFactory

  Set pWSFact = New AccessWorkspaceFactory
  Dim pWS2 As IRasterWorkspaceEx
  Set pWS2 = pWSFact.OpenFromFile(databasepath.Caption, 0)

   Dim pWSF As IWorkspaceFactory
    Set pWSF = New RasterWorkspaceFactory
    Set pWS = pWSF.OpenFromFile("F:\PhD\GIS\Temp", 0)

'Create the MathOps object
Dim pMathOp As IMathOp
Set pMathOp = New RasterMathOps

' Declare the input geoDataset1 object
Dim pinputdataset1 As IRasterDataset
Set pinputdataset1 = pWS2.OpenRasterDataset("elderlyh")

Dim pInputDataset2 As IRasterDataset
Set pInputDataset2 = pWS2.OpenRasterDataset("elderly")

    'Set output workspace
    Dim pEnv As IRasterAnalysisEnvironment
    Set pEnv = pMathOp

    Set pEnv.OutWorkspace = pWS

    'Perform the operation
    Dim pOutRaster As IRaster
    Set pOutRaster = pMathOp.Times(pinputdataset1, pInputDataset2)

    'Create a raster layer and add it into ArcMap
    Dim pOutRasLayer As IRasterLayer
    Set pOutRasLayer = New RasterLayer
    pOutRasLayer.CreateFromRaster pOutRaster = "VulnScore"
    pMap.AddLayer pOutRasLayer

End Sub