What data type is a Value Table in a geoprocessing tool?

793
4
04-30-2019 11:35 AM
BenRufenacht
New Contributor III

I am trying to run CalculateGeometryAttributes_management, but I can not figure out what data type to use for the

geometry_property[[Target Field, Property],...]. It appears to be an IEnumerable<KeyValuePair<string,string>>. I tried to use a dictionary, as it has this value type, but it gave me an error. Here is what I have:

Dictionary<string,string> items = new Dictionary<string, string> { "Area", "AREA" };
arguments1 = Geoprocessing.MakeValueArray(floodShape, items, "FEET_US", "SQUARE_FEET_US");
gpResult1 = Geoprocessing.ExecuteToolAsync("CalculateGeometryAttributes_management", arguments1, enviroment, null, null, GPExecuteToolFlags.None);

Anyone know what data type to use?

4 Replies
NobbirAhmed
Esri Regular Contributor

It is recommended that a user always check the tool's documentation page to make sure the data type of each parameter. For example the doc for the tool is here - you can jump to this page by clicking on the help button (? mark).

https://pro.arcgis.com/en/pro-app/tool-reference/data-management/calculate-geometry-attributes.htm

There you'll find the syntax:

CalculateGeometryAttributes_management (in_features, geometry_property, {length_unit}, {area_unit}, {coordinate_system})

Below the syntax, you'll see data type of each parameter, with explanation and valid values.



0 Kudos
BenRufenacht
New Contributor III

As I said in my original question, the data type listed in the documentation is value table. My question is what data type in C# corresponds to data table. I have tried KeyValuePair, array of KeyValuePairs, lists of KeyValuePairs, and dictionaries. None of these will work.

NobbirAhmed
Esri Regular Contributor

Okay, I got it now. Here is the code that runs successfully for me:

var fields = "AAA TEXT 'A A A' 255 # #;BBB LONG 'B B B' # # #;CCC DOUBLE 'C C C' # # #";

# within double quote: field_name, field_type, field_alias, field_lenght (for string)

# for multiple fields (AddFields tool), separate two fields by semicolon

I got this syntax by running the tool via tool dialog and then drag-dropping the result from History tab to Python window.

0 Kudos
Asimov
by
New Contributor III

I'm definitely late in the discussion, but it may help someone who's looking for this topic.

I had the exact same problem as @BenRufenacht and I couldn't really understand the given answer since in the geometry_property only a pair of parameters are required and type is not part of the data. So what I did was to display the tool in the geoprocessing pane, put in some parameters and from there copy the python command as shown in this screenshot:

Asimov_0-1695895342241.png

Python command resulted as follows:

arcpy.management.CalculateGeometryAttributes(
in_features="ct Particelle",
geometry_property="AREA AREA",
length_unit="",
area_unit="SQUARE_METERS",
coordinate_system=None,
coordinate_format="SAME_AS_INPUT"
)

 

Then I just passed the same to MakeValueArray as follows:

var tool_name = "management.CalculateGeometryAttributes";
var geometry_property = "AREA AREA"
var areaUnit = "Square Meters";

var val_array = Geoprocessing.MakeValueArray(new object[] { _layer, geometry_property, null, areaUnit });

return await Geoprocessing.ExecuteToolAsync(tool_name, val_array);

 

Turned out it works as intended.

Sometimes it is really so much harder than it should be to find some reference about ESRI SDK issues, like this one. I found dozens code samples about using GeoProcessing tools, repeating the same key concepts again and again (usually with using the same tools, also), but I couldn't find any documentation/reference explaining how a "ValueType" parameter should be constructed and passed...hope this helps someone.

0 Kudos