Do you need something specific?There is pretty good explanation of how to run a Geoprocessor tool here:http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Using_geoprocessing/0001000004mm000000/And the Raster Calculator:http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Members/004700002782000000/
I've been struggeling with this as well the last few days, this is the only specific proposition around, but is doesn't work for me.
First of all my geoprocessor.Execute() takes 3 arguments instead of 2, I dont know why because I've used it with 2 args in the past...
For the ToolRasterCalc arg, the Execute doesn't accept this type RasterCalculator, it wants name as string
Maybe I am using the wrong Geoprocessor, I thought there were 2, a 'GeoProcessor' and a 'Geoprocessor', but that's in c# and vb is case insensitive..
I used your code like this:
Public Sub RasterCalculator(ByVal outputRasterPath As String, ByVal expression As String)
Dim gp As New ESRI.ArcGIS.Geoprocessor.Geoprocessor
Dim toolRasterCalc As New RasterCalculator(expression, outputRasterPath)
gp.OverwriteOutput = True
Dim gpResult As IGeoProcessorResult = New GeoProcessorResult
gpResult = gp.Execute(toolRasterCalc.ToolboxName, Nothing, Nothing)
I keep getting a nullreference exception at the gp.Execute line but I don't know why...
any help here?
While having some more experience with the geoprocessors, I can suggest it's better to use an IGPProcess as the first argument of Execute(), the second arg is some default TrackCancel object that you first have to set up. So it's better to use the overloaded function with 2 arguments.
So it would look something like this (example with another tool)
1) Initalize tool object, set properties
Dim copyraster As New CopyRaster
.in_raster = inputpath
.out_rasterdataset = outputPath
.pixel_type = FrameworkConstants.RASTER_PIXEL_TYPE
2) Intialize the Geoprocessor
Dim gp2 As ESRI.ArcGIS.Geoprocessor.Geoprocessor = New ESRI.ArcGIS.Geoprocessor.Geoprocessor()
gp2.OverwriteOutput = True
gp2.AddOutputsToMap = False
3) Create IGPProcess and TrackCancel object
Dim result2 As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult = Nothing
Dim pGPProcess2 As IGPProcess = DirectCast(copyraster, IGPProcess)
Dim pTrackCancel As ITrackCancel = GetDefaultCancelTracker()
4) Execute and cast to IGeProcessorResult
result2 = DirectCast(gp2.Execute(pGPProcess2, pTrackCancel), ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult)
5) Check if object is filled and status is correct
If (result2 Is Nothing) OrElse (result2.Status <> esriJobStatus.esriJobSucceeded) Then
Throw New GeoProcessingException(GetFullToolName(copyraster), gp2)
If this doesn't work, you could sail a slightly different course and use Map Algebra instead, I prefer using this if I want to do a raster calculation
Help: ArcObjects Help for .NET developers
Retrieving data ...