I just could not get ArcHydro tool to work using ArcGIS Pro SDK. The following is a block of my code. Any hep will be greatly appreciated.
string sIputRaster = @"C:\Support\ESRI_LocalGovernment.gdb\FiveMeterSurface";
string sRaterPath = @"C:\Support\Fill.tif";
var parameters = Geoprocessing.MakeValueArray(sIputRaster, sRaterPath);
var cts = new CancellationTokenSource();
var results = await Geoprocessing.ExecuteToolAsync("Fill", parameters, null, cts.Token,
(eventName, o) =>
{
}, GPExecuteToolFlags.None);
if (results.IsFailed)
{
MessageBox.Show("Failed to create fill layer. Error " + results.ErrorCode);
return;
}
Solved! Go to Solution.
Hi,
Spatial Analyst has its own way of setting parameters for tools which have return value. They order differs in Python and .NET. Because Fill tool has 2 input parameters and 1 output, so output parameter could be in third place. You need to check it. Set for example 1 for z_limit.
https://pro.arcgis.com/en/pro-app/latest/tool-reference/spatial-analyst/fill.htm
Another one thing I am not sure about geoprocessing tool name. It could be named like "Fill_sa" as other spatial analyst tools which I have used. For example "Reclassify_sa", "RasterCalculator_sa". There is no description about that.
Add validation checking to your geoprocessing call like in code below:
string sIputRaster = @"C:\Support\ESRI_LocalGovernment.gdb\FiveMeterSurface";
string sRaterPath = @"C:\Support\Fill.tif";
var parameters = Geoprocessing.MakeValueArray(sIputRaster, 1, sRaterPath);
var cts = new CancellationTokenSource();
var results = await Geoprocessing.ExecuteToolAsync("Fill_sa", parameters, null, cts.Token,
(eventName, o) =>
{
System.Diagnostics.Debug.WriteLine($@"GP event: {eventName}");
if (eventName == "OnMessage")
{
IGPMessage gpMsg = o as IGPMessage;
if (gpMsg != null)
{
Logger.Info(gpMsg.Text);
}
else
{
Logger.Info($@"{o.ToString()}");
}
}
if (eventName == "OnValidate")
{
List<IGPMessage> gpMsgs = (o as IGPMessage[]).ToList();
if (gpMsgs != null)
{
foreach (var gpMsg in gpMsgs)
{
if (gpMsg.ErrorCode == 0)
{
continue;
}
// Fill with your logging
}
}
else
{
// Fill with your logging
}
}
if (eventName == "OnProgressMessage")
{
// Fill with your logging
}
}, GPExecuteToolFlags.None);
if (results.IsFailed)
{
MessageBox.Show("Failed to create fill layer. Error " + results.ErrorCode);
return;
}
Hi,
Spatial Analyst has its own way of setting parameters for tools which have return value. They order differs in Python and .NET. Because Fill tool has 2 input parameters and 1 output, so output parameter could be in third place. You need to check it. Set for example 1 for z_limit.
https://pro.arcgis.com/en/pro-app/latest/tool-reference/spatial-analyst/fill.htm
Another one thing I am not sure about geoprocessing tool name. It could be named like "Fill_sa" as other spatial analyst tools which I have used. For example "Reclassify_sa", "RasterCalculator_sa". There is no description about that.
Add validation checking to your geoprocessing call like in code below:
string sIputRaster = @"C:\Support\ESRI_LocalGovernment.gdb\FiveMeterSurface";
string sRaterPath = @"C:\Support\Fill.tif";
var parameters = Geoprocessing.MakeValueArray(sIputRaster, 1, sRaterPath);
var cts = new CancellationTokenSource();
var results = await Geoprocessing.ExecuteToolAsync("Fill_sa", parameters, null, cts.Token,
(eventName, o) =>
{
System.Diagnostics.Debug.WriteLine($@"GP event: {eventName}");
if (eventName == "OnMessage")
{
IGPMessage gpMsg = o as IGPMessage;
if (gpMsg != null)
{
Logger.Info(gpMsg.Text);
}
else
{
Logger.Info($@"{o.ToString()}");
}
}
if (eventName == "OnValidate")
{
List<IGPMessage> gpMsgs = (o as IGPMessage[]).ToList();
if (gpMsgs != null)
{
foreach (var gpMsg in gpMsgs)
{
if (gpMsg.ErrorCode == 0)
{
continue;
}
// Fill with your logging
}
}
else
{
// Fill with your logging
}
}
if (eventName == "OnProgressMessage")
{
// Fill with your logging
}
}, GPExecuteToolFlags.None);
if (results.IsFailed)
{
MessageBox.Show("Failed to create fill layer. Error " + results.ErrorCode);
return;
}
Thanks a lot for your help. I am able to get it work now. The key is the GP tool name. It should be "Fill_sa" as you indicated. But it only takes 2 parameters in Pro SDK though. It would be better if users can specify z_limit.
Try to specify z_limit as third parameter. Sometimes spatial analyst tools inserts output parameter in second or in third position. So if you have found that output parameter is second then z_limit parameter could be third