Skip to main content
4 of 5
edited tags
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

ArcGIS Pro Slope Tool failing with Output measurement and Z factor parameter in C#

The code below with 3 parameters fails to run slope tool and get expected result

 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?