Select to view content in your preferred language

Use ExecuteToolAsync to run TopoToRaster

437
4
03-23-2025 10:32 AM
sz66666
Emerging Contributor

Hi,

I'm trying to use ExecuteToolAsync () to run the tool TopoToRaster but I could not figure it out. 

Not sure what the parameters are required to run it.
can someone help out please?

0 Kudos
4 Replies
SumitMishra_016
Frequent Contributor

Hi @sz66666 ,

Can you try like this:

// Create the parameter array for the TopoToRaster tool
var parameters = Geoprocessing.MakeValueArray(
	inTopoFeatures,
	cellSize,
	extent,
	margin,
	minimumZValue,
	maximumZValue,
	enforce,
	dataType,
	maximumIterations,
	roughnessPenalty,
	discreteErrorFactor,
	verticalStandardError,
	tolerance1,
	tolerance2,
	outStreamFeatures,
	outSinkFeatures,
	outDiagnosticFile,
	outParameterFile,
	profilePenalty,
	outResidualFeature,
	outStreamCliffErrorFeature,
	outContourErrorFeature
);

// Set execute flags
GPExecuteToolFlags executeFlags = GPExecuteToolFlags.AddOutputsToMap |
								 GPExecuteToolFlags.GPThread |
								 GPExecuteToolFlags.AddToHistory |
								 GPExecuteToolFlags.RefreshProjectItems;

// Execute the TopoToRaster tool
IGPResult gpResult = await Geoprocessing.ExecuteToolAsync("SpatialAnalyst.TopoToRaster", parameters, null, null, null, executeFlags);

// Show the messages
Geoprocessing.ShowMessageBox(gpResult.Messages, "TopoToRaster Messages", gpResult.IsFailed ? GPMessageBoxStyle.Error : GPMessageBoxStyle.Default);
0 Kudos
sz66666
Emerging Contributor

Thank you for the reply. by any chance you know what should be passed as the input feature. The documentation said it needs to specify the elevation field. In my case it will be the TopoPointElevation but Im not sure how to create that in C#.

below is the explanation of the input feature :

Each feature input can have a field specified that contains the z-values and one of six types specified.

  • Feature layer—The input feature dataset.
  • Field—The name of the field that stores the attributes, where appropriate.
  • Type—The type of input feature dataset.

    and below is the python example it provides:
    outTTR = TopoToRaster([TopoPointElevation([['spots', 'spot_meter']]), TopoContour([['contours', 'spot_meter']]), TopoCliff(['cliff'])], 60, "#", "#", "#", "#", "NO_ENFORCE")

https://pro.arcgis.com/en/pro-app/3.3/tool-reference/spatial-analyst/topo-to-raster.htm

 

0 Kudos
sz66666
Emerging Contributor

up

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

I attached a sample Button OnClick method that includes all parameters and environment settings to call the 'Topo to Raster' GP Tool.  To figure out in what form to pass in the parameter values I usually use the following approach:

- I run the GP Tool manually and define all needed parameters

- After the GP Tool completes, I click the "Open History" link to open the Geoprocessing History tab

- I right click on the GP Tool and select the "Copy Python Command" from the context menu.

- I then paste the 'Python Command' syntax into a text editor to see the parameter value formats.

- I use the python command's parameter format to fill in the parameters for the ExecuteToolAsync call