I'm having a hard time subtracting two rastera with ArcObjects sdk 10.1. I keep getting a null reference exception at the gp.execute() method, but I can't figure out where the problem is, I recall setting other arguments to nothing in the past so don't think this would be the problem

I'm using both raster paths in the expression and I'm not sure if the syntax will be correctly parsed

Input values are in this test method (don't mind the incomplete assert, I check it manually in ArcMap)

Public Sub RasterCalculatorTest_ObjectIsFiled_NotIsNothing()
    Dim target As CalculateOVRaster = New CalculateOVRaster()
    Dim rasterPath1 As String = rasterGdbPath & "\" & "subvakken_hpo"
    Dim rasterPath2 As String = dhmPath & "\" & dhmName
    Dim expression As String = "'" & rasterPath1 & "'-'" & rasterPath2 & "'"
    Dim outputPath As String = rasterGdbPath
    target.RasterCalculator(outputPath, expression)
End Sub

Main method:

 Public Sub RasterCalculator(ByVal outputRasterPath As String, ByVal expression As String)
    Dim gp As GeoProcessor = New GeoProcessorClass
    Dim toolRasterCalc As New RasterCalculator(expression, outputRasterPath)
    gp.OverwriteOutput = True

    Dim gpResult As IGeoProcessorResult = New GeoProcessorResult
    gpResult = gp.Execute(toolRasterCalc.ToolboxName, Nothing, Nothing)     

End Sub
  • There appears to be a problem with your quoting, the Raster Calculator tool uses "raster" quoting and you're supplying 'raster' quoting.. see stackoverflow.com/questions/7239872/… about changing that. target is CalculateOVRaster but I can't find any reference to that unless that's what your program is called and you're attempting to multiprocess, Esri is not thread safe so just call the sub as normal (perhaps change to Dim gp As GeoProcessor = New GeoProcessorClass(), in C# the brackets are important but perhaps not so much in VB) – Michael Stimson Jun 22 '15 at 0:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.