ExecuteToolAsync CalculateGeometryAttributes Error

175
4
Jump to solution
08-16-2022 09:21 AM
PeteVitt
Occasional Contributor III

Hi - I'm making an ExecuteToolAsync call to CalculateGeometryAttributes tool using ArcGIS Pro SDK 3.0 and am getting a System.Linq.Enumerable.WhereListIterator<ArcGIS.Desktop.Core.Geoprocessing.IGPMessage error.  I've based my call on the tool reference located here: https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-geometry-attribute...

I believe the error is related to the geometry_property parameter [[Field, Property],...]

my code is here:

 var progDlg = new ProgressDialog("Processing Areas", "Cancel", 100, true);
            progDlg.Show();
            var inputLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().First(l => l.Name.Equals(LayerNames.TempLAClip));
            var toolName = "management.CalculateGeometryAttributes";//based on my GP tool cache 
            var fieldParams = new List<string>() { "Ft2", "AREA" };
            var fieldParamList = new List<List<string>>();//this appears to be a list of lists (I also tried just using a list and got same error
            fieldParamList.Add(fieldParams);
            var units = "SQUARE_FEET_US";
            var calcParams = await QueuedTask.Run(() =>
            {
                return Geoprocessing.MakeValueArray(
                    new object[] { inputLayer, fieldParamList, units });
            });
            IGPResult result = await Geoprocessing.ExecuteToolAsync(toolName, calcParams, null, new CancelableProgressorSource(progDlg).Progressor, GPExecuteToolFlags.Default);

 if (result.IsCanceled)//fails or is canceled
            {
                _vm.StatusMessage = "Calculation Canceled";
                return false;
            }
            else if (result.IsFailed)//get error message here
            {
                _vm.StatusMessage = "Calculation Failed";
                return false;
            }
            else
            {
                return true;
            }

 any suggestions of how to fix this error?

 

Thanks

 

Pete

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Pete,

 I think that the problem is that you are specifying the 'length' unit instead of the 'area' unit parameter.  The following snippet worked for me (notice that i inserted "" as the length unit before the area parameter):

 

var inputLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().First(l => l.Name.Equals(layerName));
var toolName = "management.CalculateGeometryAttributes";//based on my GP tool cache 
var fieldParams = "TheInteger AREA";
var unit = "SQUARE_METERS";
var calcParams = Geoprocessing.MakeValueArray(
      new object[] { inputLayer, fieldParams, "", unit, MapView.Active.Map.SpatialReference });
IGPResult result = await Geoprocessing.ExecuteToolAsync(toolName, calcParams, null, new CancelableProgressorSource(progDlg).Progressor, GPExecuteToolFlags.Default);

 

 

View solution in original post

4 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Pete,

 I think that the problem is that you are specifying the 'length' unit instead of the 'area' unit parameter.  The following snippet worked for me (notice that i inserted "" as the length unit before the area parameter):

 

var inputLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().First(l => l.Name.Equals(layerName));
var toolName = "management.CalculateGeometryAttributes";//based on my GP tool cache 
var fieldParams = "TheInteger AREA";
var unit = "SQUARE_METERS";
var calcParams = Geoprocessing.MakeValueArray(
      new object[] { inputLayer, fieldParams, "", unit, MapView.Active.Map.SpatialReference });
IGPResult result = await Geoprocessing.ExecuteToolAsync(toolName, calcParams, null, new CancelableProgressorSource(progDlg).Progressor, GPExecuteToolFlags.Default);

 

 

PeteVitt
Occasional Contributor III

Thanks Wolf, that solved the problem

0 Kudos
CharlesMacleod
Esri Regular Contributor

When faced with what syntax to use when running GP tools via ExecuteToolAsync I typically follow the same approach which u may find useful:

1. Open the GP Tool Dialog.

2. Manually configure the GP Tool Dialog with the desired options (may be some trial and error here)

3. Run the tool

4. Click on "View Details", then "Parameters" to view the parameters the tool used based on my dialog options.

5. Transfer the options from the "View Details" parameters to the addin code. Typically, ";" (semi-colons) in the output params indicates an input list. Again, u may have a bit of fiddling here to get this right. However, every parameter that is shown on the View Details with an assigned value should have a corresponding parameter variable in your addin code.

For Calculate Geometry Attributes, this looks like:

1. Open the dialog and configure:

tool_dialog.png

2. Run the tool, "View Details"...shows these parameter values based on my selections:

view_details_params.png

3. Transfer the parameters to the addin code:

internal class RunCalcGeomAttribs : Button {
 protected override async void OnClick() {
   var inputLayer =
     MapView.Active.Map.GetLayersAsFlattenedList()
      .OfType<FeatureLayer>().First(l => l.Name == "Portland_PD_Precincts");
   var toolName = "management.CalculateGeometryAttributes";

   var geom_attribs = new List<string>() {
     "AREA AREA_GEODESIC", "LENGTH PERIMETER_LENGTH_GEODESIC", "VERTICES POINT_COUNT"
   };
   var length_unit = "FEET_US";
   var area_unit = "SQUARE_FEET_US";

   var calcParams = Geoprocessing.MakeValueArray(
       new object[] { inputLayer, geom_attribs, length_unit, area_unit });

   IGPResult result = await Geoprocessing.ExecuteToolAsync(
         toolName, calcParams, null, CancelableProgressor.None,
              GPExecuteToolFlags.InheritGPOptions);

   var str = "No errors";
   if (result.IsFailed) {
     str = string.Join(',', result.ErrorMessages?.Select(
             m => m.Text).ToList() ?? new List<string>());
   }
   System.Diagnostics.Debug.WriteLine(str);
 }
}

Notice that the format of the params in my code are different than yours based on what the View Details dialog provided.

4. This gives the final output:

geom_attrib_out.png

You can always double-check if your params are correct by calling Geoprocessing.OpenToolDialog or OpenToolDialogAsync - it should give the same tool dialog view "pre-configured" with the same options. If OpenToolDialog doesn't open the tool dialog correctly then chances are that GP.ExecuteToolAsync won't work correctly either.

 ...
 var calcParams = Geoprocessing.MakeValueArray(
   new object[] { inputLayer, geom_attribs, length_unit, area_unit });
 //use OpenToolDialog to check param format is correct
 Geoprocessing.OpenToolDialogAsync(toolName, calcParams);

 

 

 

 

 

PeteVitt
Occasional Contributor III

very helpful

0 Kudos