Hi - I'm not having success running the Summarize Attributes tool in the GeoAnalytics Desktop Tools using ExecuteToolAsync in ArcPro sdk 3.0. Below is my code. Am I approaching this the correct way? I'm not sure if the tool name is correct, and I don't think the parameters I'm passing are correct either
//summarize landscape classifications
var progSumDlg = new ProgressDialog("Running Geoprocessing Tool", "Cancel", 100, true);
progSumDlg.Show();
var sum_tool_name = "geoanalytics.Summarize";
//layer to summarize
var summarizeLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().First(l => l.Name.Equals("test_clip"));
//field to classifiy and field to get stats for
Table table = summarizeLayer.GetTable();
TableDefinition tableDefinition = table.GetDefinition();
Field classField = tableDefinition.GetFields().FirstOrDefault(x => x.Name.Contains("Class_name"));
Field statField = tableDefinition.GetFields().FirstOrDefault(x => x.Name.Contains("Ft2"));
//output table
var out_table = System.IO.Path.Combine(gdb, "test_clip_summary");
var sum_params = await QueuedTask.Run(() =>
{
return Geoprocessing.MakeValueArray(new object[] { summarizeLayer, out_table, classField, statField});
});
await Geoprocessing.ExecuteToolAsync(sum_tool_name, sum_params,
null, new CancelableProgressorSource(progSumDlg).Progressor, GPExecuteToolFlags.Default);
thanks
Pete
Solved! Go to Solution.
First thing I notice is that the toolname is "SummarizeAttributes" rather than "Summarize" as u have it so that needs to be changed.
Second thing I noticed was that using the toolname "geoanalytics.SummarizeAttributes" I actually got a _server_ flavor of the tool and not the _desktop_ flavor (not that I knew there were two as I am not personally familiar with the Geoanalytics toolbox).
I wonder if you have a similar issue and are invoking the Geoanalytics server tool and not the desktop tool?
Well, eventually, I ended up with a toolname of "gapro.SummarizeAttributes" which seemed to do the trick and invoke the desktop toolbox. You can try my code below. (I am using the "Interacting with Maps.gdb\Crimes" dataset from the pro community sample data fyi).
internal class GPTestButton : Button {
protected async override void OnClick()
{
var sum_tool_name = "gapro.SummarizeAttributes";
//var sum_tool_name = "geoanalytics.SummarizeAttributes";
var extent = MapView.Active.Extent;
var summarizeLayer = MapView.Active.Map.GetLayersAsFlattenedList()
.OfType<FeatureLayer>().FirstOrDefault(l => l.Name == "Crimes");
if (summarizeLayer == null) return;
var gdb = Project.Current.DefaultGeodatabasePath;
//output table
var out_table = System.IO.Path.Combine(gdb, "crimes_summary");
var fields = new List<string>() { "Major_Offense_Type", "Police_Precinct" };
var summary_fields = new List<string>() { "Major_Offense_Type COUNT" };
var sum_params = await QueuedTask.Run(() =>
{
return Geoprocessing.MakeValueArray(
new object[] { summarizeLayer, out_table, fields, summary_fields });
});
await Geoprocessing.ExecuteToolAsync(sum_tool_name, sum_params,
null, CancelableProgressor.None,
GPExecuteToolFlags.InheritGPOptions);
//Or open the dialog
//Geoprocessing.OpenToolDialog(sum_tool_name, sum_params);
}
}
Gives:
This is the tool dialog invoked via Geoprocessing.OpenToolDialog
Note: To resolve the toolname I had to look in the GP tool cache to see what it (GP) was looking for. You can find that here: C:\Users\your_username\AppData\Local\ESRI\Local Caches. Despite their rather intimidating appearance they are just text files. Just drag and drop one of them into notepad. I searched for "SummarizeAttributes" and came up with two hits: "geoanalytics.SummarizeAttributes" and "gapro.SummarizeAttributes". As I had already tried "geoanalytics.SummarizeAttributes", I went with the other one.
Hi,
I have wrote about geoprocessing sdk help for .Net developers few times but unsuccessful.
Geoprocessing tool name should be constructed like "SummarizeAttributes_geoanalytics".
MakeValueArray method doesn't need MCT. It should look like this:
List<string> fields = new List<string() { "Class_name", "Ft2" };
var sum_params = Geoprocessing.MakeValueArray(summarizeLayer, out_table, $"{string.Join(",", fields)}");
You can use the syntax "geoanalytics.SummarizeAttributes" for tool names.
You will need to put a couple of lines inside of a QueuedTask.Run
Table table = summarizeLayer.GetTable();
TableDefinition tableDefinition = table.GetDefinition();
Field classField = tableDefinition.GetFields().FirstOrDefault(x => x.Name.Contains("Class_name"));
Field statField = tableDefinition.GetFields().FirstOrDefault(x => x.Name.Contains("Ft2"));
I changed the tool name to "geoanalytics.SummarizeAttributes"
I tried two ways to call the tool as suggested:
1) with field objects inside QueuedTask
var sum_params = await QueuedTask.Run(() =>
{
Table table = summarizeLayer.GetTable();
TableDefinition tableDefinition = table.GetDefinition();
Field classField = tableDefinition.GetFields().FirstOrDefault(x => x.Name.Contains("Class_name"));
Field statField = tableDefinition.GetFields().FirstOrDefault(x => x.Name.Contains("Ft2"));
var out_table = System.IO.Path.Combine(gdb, "test_clip_summary");
return Geoprocessing.MakeValueArray(new object[] { summarizeLayer, out_table, classField, statField });
});
await Geoprocessing.ExecuteToolAsync(sum_tool_name, sum_params,
null, new CancelableProgressorSource(progSumDlg).Progressor, GPExecuteToolFlags.Default);
2) with fields as strings:
List<string> fields = new List<string>() { "Class_name", "Ft2" };
var out_table = System.IO.Path.Combine(gdb, "test_clip_summary"); ;
var sum_params = Geoprocessing.MakeValueArray(summarizeLayer, out_table, $"{string.Join(",", fields)}");
await Geoprocessing.ExecuteToolAsync(sum_tool_name, sum_params,
null, new CancelableProgressorSource(progSumDlg).Progressor, GPExecuteToolFlags.Default);
in both cases the summary table is not being generated.
I've based my call to 'Summarize Attributes' on the Parameters section of the Tool Reference located here:
https://pro.arcgis.com/en/pro-app/2.8/tool-reference/big-data-analytics/summarize-attributes.htm
I haven't so far been able to find a snippet or example of the tool being called by the sdk
Pete
The first thing you'll want to do is to check in the ArcGIS Pro Geoprocessing History to see if the tool ran properly and what errors it encountered if it didn't. You should also be able to tell whether your inputs are what you expected.
I'm not seeing any of the sdk initiated geoprocessing calls (even successful ones) in the geoprocessing history
You can use the flag GPExecuteToolFlags.AddToHistory. This is an example of one of my calls
IGPResult result = await Geoprocessing.ExecuteToolAsync("management.Dissolve", Geoprocessing.MakeValueArray(arguments.ToArray()), null, null, null, GPExecuteToolFlags.AddToHistory);
First thing I notice is that the toolname is "SummarizeAttributes" rather than "Summarize" as u have it so that needs to be changed.
Second thing I noticed was that using the toolname "geoanalytics.SummarizeAttributes" I actually got a _server_ flavor of the tool and not the _desktop_ flavor (not that I knew there were two as I am not personally familiar with the Geoanalytics toolbox).
I wonder if you have a similar issue and are invoking the Geoanalytics server tool and not the desktop tool?
Well, eventually, I ended up with a toolname of "gapro.SummarizeAttributes" which seemed to do the trick and invoke the desktop toolbox. You can try my code below. (I am using the "Interacting with Maps.gdb\Crimes" dataset from the pro community sample data fyi).
internal class GPTestButton : Button {
protected async override void OnClick()
{
var sum_tool_name = "gapro.SummarizeAttributes";
//var sum_tool_name = "geoanalytics.SummarizeAttributes";
var extent = MapView.Active.Extent;
var summarizeLayer = MapView.Active.Map.GetLayersAsFlattenedList()
.OfType<FeatureLayer>().FirstOrDefault(l => l.Name == "Crimes");
if (summarizeLayer == null) return;
var gdb = Project.Current.DefaultGeodatabasePath;
//output table
var out_table = System.IO.Path.Combine(gdb, "crimes_summary");
var fields = new List<string>() { "Major_Offense_Type", "Police_Precinct" };
var summary_fields = new List<string>() { "Major_Offense_Type COUNT" };
var sum_params = await QueuedTask.Run(() =>
{
return Geoprocessing.MakeValueArray(
new object[] { summarizeLayer, out_table, fields, summary_fields });
});
await Geoprocessing.ExecuteToolAsync(sum_tool_name, sum_params,
null, CancelableProgressor.None,
GPExecuteToolFlags.InheritGPOptions);
//Or open the dialog
//Geoprocessing.OpenToolDialog(sum_tool_name, sum_params);
}
}
Gives:
This is the tool dialog invoked via Geoprocessing.OpenToolDialog
Note: To resolve the toolname I had to look in the GP tool cache to see what it (GP) was looking for. You can find that here: C:\Users\your_username\AppData\Local\ESRI\Local Caches. Despite their rather intimidating appearance they are just text files. Just drag and drop one of them into notepad. I searched for "SummarizeAttributes" and came up with two hits: "geoanalytics.SummarizeAttributes" and "gapro.SummarizeAttributes". As I had already tried "geoanalytics.SummarizeAttributes", I went with the other one.
Thanks Charles that worked
Pete