1

The code below with 3 parameters fails to run slope tool and get expected result. No error is shown. Just expected result doesn't come out.

 public SlopeTool(string inRaster, string outRasterName, string workspace, string 
 prjFilePath)
 {
 _inRaster = inRaster;
 _outRasterName = outRasterName;
 _workspace = workspace;
 _prjFilePath = prjFilePath;
 }

 public async Task<IGpResult> ExecuteAsync()
 {
 try
 {
     var slopeToolParameters = Geoprocessing.MakeValueArray(
         _inRaster, "PERCENT_RISE", 1
     );

     var gpResult = await Geoprocessing.ExecuteToolAsync("sa.Slope", 
     slopeToolParameters);

     if (gpResult.IsFailed)
     {
         MessageBox.Show("Tool Failed");
     }
     return new GpResult(gpResult);

 }
 catch (Exception ex)
 {
     MessageBox.Show($@"Error during Slope Tool operation: {ex.Message}");
     return new GpResult(null);
 }
 }

But this code below runs and succeeds with the single parameter

public SlopeTool(string inRaster, string outRasterName, string workspace, string 
prjFilePath)
{
 _inRaster = inRaster;
 _outRasterName = outRasterName;
 _workspace = workspace;
 _prjFilePath = prjFilePath;
}

public async Task<IGpResult> ExecuteAsync()
{
 try
 {
     var slopeToolParameters = Geoprocessing.MakeValueArray(
         _inRaster
     );

     var gpResult = await Geoprocessing.ExecuteToolAsync("sa.Slope", 
     slopeToolParameters);

     if (gpResult.IsFailed)
     {
         MessageBox.Show("Tool Failed");
     }
     return new GpResult(gpResult);

    }
    catch (Exception ex)
    {
     MessageBox.Show($@"Error during Slope Tool operation: {ex.Message}");
     return new GpResult(null);
    }
 }

I can also run it in ArcGIS Pro Python command line this way

arcpy.sa.Slope('DEM_AB_Clip1.tif', 'PERCENT_RISE', 1)

What is the problem in my 1st code with 3 parameters and how to get expected result?

2
  • 2
    The code looks OK to me, so what is the error message? You say the python command works OK are you running the c# code on the same DEM?
    – Hornbydd
    Commented Jun 2 at 13:03
  • What was your expected result? How did your observed result deviate from that?
    – PolyGeo
    Commented Jun 13 at 5:52

0