Geoprocessing.ExecuteToolAsync C# SYNTAX

2891
13
Jump to solution
04-19-2018 09:50 AM
MikeRatcliffe
Occasional Contributor

After reviewing available examples and references (only available in Python), I am unable to pass a successful Geoprocessing.MakeValueArray into the ExecuteToolAsync.  I am confident it is a C# #syntax issue, and need some help...

Example Code:

main_lyr.Select(qf, SelectionCombinationMethod.New);

var in_table = main_lyr;
var out_table = Path.Combine(Project.Current.DefaultGeodatabasePath, GVar.FtrLyr + " Results");
var statistics_fields = "FEET, Sum"; //[['FEET', 'SUM']]";
var case_field = "Diameter"; // "['Diameter']";

var args = Geoprocessing.MakeValueArray(in_table, out_table, statistics_fields, case_field);

var sp_ref = SpatialReferenceBuilder.CreateSpatialReference(102629); // NAD83 SP AL E FIPS 0101 Feet

var envi = Geoprocessing.MakeEnvironmentArray(outputCoordinateSystem: sp_ref);

Geoprocessing.ExecuteToolAsync("Statistics_analysis", args, envi, null, null, GPExecuteToolFlags.Default);

0 Kudos
1 Solution

Accepted Solutions
MikeRatcliffe
Occasional Contributor

Firstly, THAT worked! "FEET Sum"

Just to clarify, the syntax documented here in the arcpy environment:

Summary Statistics—Help | ArcGIS Desktop 

is

[["Shape_Area", "SUM"]]

Thank you.

View solution in original post

0 Kudos
13 Replies
BalajiVeera
Occasional Contributor

Refer these two examples of ExecuteToolAsync method overloads from SDK document, either wait till complete the execution or execute with optional event handler

ArcGIS Pro 2.1 API Reference Guide 

ArcGIS Pro 2.1 API Reference Guide 

0 Kudos
MikeRatcliffe
Occasional Contributor

Thanks. I am aware of the SDK examples you reference above.  They do not help with my issue.  The issue is passing the correct syntax to the "Statistics_analysis" geoprocessing tool successfully from the example code above.  All of the ESRI tool references in ArcGIS Pro for "Statistics_analysis" have Python syntax.

0 Kudos
NobbirAhmed
Esri Regular Contributor

As your sp_ref is an object you need to pass it through MakeValueArray(..). Could you please try with these changes:

var sp_ref = Geoprocessing.MakeValueArray(SpatialReferenceBuilder.CreateSpatialReference(102629));

var args = Geoprocessing.MakeValueArray(in_table, out_table, statistics_fields, case_field);

var envi = Geoprocessing.MakeEnvironmentArray(outputCoordinateSystem: sp_ref);

If you follow the documentation you'll find which objects are supported directly.

https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Geoprocessing#create-an-array-of-environment...

If you scroll down the above documentation you'll find this example:

// example of using ArcGIS.Core.Geometry.SpatialReference objectvar spatial_ref = await QueuedTask.Run(() => {     return SpatialReferenceBuilder.CreateSpatialReference(3857); });// call MakeValueArray on spatial_ref so that ExecuteToolAsync can internally use the objectvar sr_param = Geoprocessing.MakeValueArray(spatial_ref);
0 Kudos
MikeRatcliffe
Occasional Contributor

Thanks, Nobbir.

As before (passing sp_ref as an object), the process throws no exception, yet produces no output.  It just blocks the main application, then releases it after some time.

0 Kudos
NobbirAhmed
Esri Regular Contributor

Have you used your code or the code in the sample? In the sample code (from the documentation link) a QueuedTask.Run(...) is used to created the spatial reference object.

0 Kudos
MikeRatcliffe
Occasional Contributor

all of the example code is contained in an await QueuedTask.Run(()=> {example code});

0 Kudos
NobbirAhmed
Esri Regular Contributor

Just to be sure that issue is NOT caused by other parameter settings, I'm asking - have you called MakeValueArray on the spatial_ref object before passing it to MakeEnvironmentArray?

var spatial_ref = await QueuedTask.Run(() => {    

       return SpatialReferenceBuilder.CreateSpatialReference(3857);

});

// call MakeValueArray on spatial_ref so that ExecuteToolAsync can internally use the object

var sr_param = Geoprocessing.MakeValueArray(spatial_ref);

0 Kudos
MikeRatcliffe
Occasional Contributor

Yes, I am passing the spatial reference as an object to a value array to the environment.

present code:

var in_table = main_lyr;
var out_table = Path.Combine(Project.Current.DefaultGeodatabasePath, "Results");


var statistics_fields = "[[FEET], {Sum}]]";     *****syntax of these variables is assumed to be the failure*****
var case_field = "[Diameter]";                      ****this is the syntax provided by ESRI tool reference****                   

var args = Geoprocessing.MakeValueArray(in_table, out_table, statistics_fields, case_field);

var sp_ref = Geoprocessing.MakeValueArray(SpatialReferenceBuilder.CreateSpatialReference(102629)); // NAD83 SP AL E FIPS 0101 Feet

var envi = Geoprocessing.MakeEnvironmentArray(outputCoordinateSystem: sp_ref);

Geoprocessing.ExecuteToolAsync("Statistics_analysis", args, envi, null, null, GPExecuteToolFlags.Default);

0 Kudos
NobbirAhmed
Esri Regular Contributor

Could you please try this way (without a comma between FEET and Sum so that it matches Python syntax)?

var statistics_fields = "FEET Sum";

0 Kudos