Select to view content in your preferred language

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

203
0
05-18-2024 12:22 PM
Shahadat_1200
New Contributor

The code below with parameters in 14th line 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 parameter in 14th line 

 

 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 and how to get expected result ?

0 Kudos
0 Replies