Hi,
I am trying to perform a trace operation by using the Trace tool in Utility Network toolbox and get a connectivity graph as result for ArcGIS 2.9 SDK. (here's my previous question on the same topic)
I am referring to the arcpy Python function (Trace (Utility Network)—ArcGIS Pro | Documentation) to view the list of parameters to use in the Geoprocessing.ExecuteToolAsync function. The code snippet is as follows:
var parameters = Geoprocessing.MakeValueArray(
"D:\\MyProject.gdb\\Communications",
"UPSTREAM", //trace type
"D:\\MyProject\\Default.gdb\\UN_Temp_Starting_Points", //starting points
null, //barriers
"Communications", //domain_network
"Cable", //tier
null, //target tier
null, //subnetwork name
null, //shortest_path_network_attribute_name
false, //"EXCLUDE_CONTAINERS",
false, //"EXCLUDE_CONTENT",
false, //"EXCLUDE_STRUCTURES",
true, //VALIDATE_CONSISTENCY
null, //condition_barriers
null, //function_barriers
"BOTH_JUNCTIONS_AND_EDGES",//traversability_scope
null, //filter_barriers
null, //filter_function_barriers
"BOTH_JUNCTIONS_AND_EDGES",//filter_scope
null,//filter_bitset_network_attribute_name
false,//filter_nearest
null, //nearest_count
null, //nearest_cost_network_attribute
null,//nearest_categories
null,//nearest_assets
null,//functions
null,//propagators
null,//output_assettypes
null,//output_conditions
false,//include_isolated_features
false,//ignore_barriers_at_starting_points
false,//include_up_to_first_spatial_container
"ELEMENTS CONNECTIVITY"//result_types
);
GPExecuteToolFlags executeFlags = GPExecuteToolFlags.AddOutputsToMap | GPExecuteToolFlags.GPThread | GPExecuteToolFlags.AddToHistory;
IGPResult result = await Geoprocessing.ExecuteToolAsync("un.Trace", parameters, null, null, null, executeFlags);
return result;
Here are my questions:
1. I want to pass only the following parameters to the GP trace tool: utility network, trace type, starting points, domain, tier and the result types. How can I set only these parameters and leave the rest to default? (This does not look possible since params args[] of MakeValueArray does not support named parameters)
2. If I have a list of Utility Network elements, how can I pass them to the starting points parameter of this function?
Solved! Go to Solution.
The function works now and a .json file with elements connectivity is created.
I had to pass all the parameters, including default values - I ran the Trace geoprocessing tool in ArcGIS Pro and referred to its Python command to get the correct parameter values and used it in my C# code.
The parameter values list of Utility Network Trace tool for reference:
var parameters = Geoprocessing.MakeValueArray(
"D:\\MyProject.gdb\\Communications",
"UPSTREAM",
"D:\\MyProject\\Default.gdb\\UN_Temp_Starting_Points",
null,
"Communications",//domain_network,
"Cable",//tier
"", //target tier
"", //subnetwork name
"", //shortest_path_network_attribute_name
"EXCLUDE_CONTAINERS",
"EXCLUDE_CONTENT",
"EXCLUDE_STRUCTURES",
"INCLUDE_BARRIERS",
"VALIDATE_CONSISTENCY",
null, //condition_barriers
null, //function_barriers
"BOTH_JUNCTIONS_AND_EDGES",//traversability_scope
null, //filter_barriers
null, //filter_function_barriers
"BOTH_JUNCTIONS_AND_EDGES",//filter_scope
"",//filter_bitset_network_attribute_name
"DO_NOT_FILTER",//filter_nearest
null, //nearest_count
"", //nearest_cost_network_attribute
null,//nearest_categories
null,//nearest_assets
null,//functions
null,//propagators
null,//output_assettypes
null,//output_conditions
//in_utility_network2,//output utility
"EXCLUDE_ISOLATED_FEATURES",
"DO_NOT_IGNORE_BARRIERS_AT_STARTING_POINTS",
"DO_NOT_INCLUDE_UP_TO_FIRST_SPATIAL_CONTAINER",
"CONNECTIVITY;SELECTION",//result_types
"NEW_SELECTION",
"CLEAR_ALL_PREVIOUS_TRACE_RESULTS",
"", //trace name
"Trace_Results_Aggregated_Points",
"Trace_Results_Aggregated_Lines",
"Trace_Results_Aggregated_Polygons",
"TRACE_INDETERMINATE_FLOW",
"DO_NOT_VALIDATE_LOCATABILITY",
"DO_NOT_USE_TRACE_CONFIGURATION",
"", //trace config name
"D:\\ArcGIS\\Projects\\MyProject\\connectivity.json",
"RUN_SYNCHRONOUSLY"
);
Hi KarthikAditya,
For the required parameters, you cannot set it to default, but for the optional parameters, you can just put "" to keep it empty and set it as default. I would recommend returning your parameters in a block and then using the parameter variable in your ExecuteToolAsync() method to make your code cleaner and easier to read.
var ParameterArray = await QueuedTask.Run(() =>
/{
return Geoprocessing.MakeValueArray("un.Trace", parameters, "", "", "");
});
IGPResult result = await Geoprocessing.ExecuteToolAsync("geoprocessing tool you want to use here(e.g. management.SelectLayerByLocation)",ParameterArray);
I hope that helps.
Thank you for your suggestion. However, when I pass empty strings "" to optional parameters to set them to default, I get the above error. My guess is that its not allowed. Any suggestion will be much appreciated.
The function works now and a .json file with elements connectivity is created.
I had to pass all the parameters, including default values - I ran the Trace geoprocessing tool in ArcGIS Pro and referred to its Python command to get the correct parameter values and used it in my C# code.
The parameter values list of Utility Network Trace tool for reference:
var parameters = Geoprocessing.MakeValueArray(
"D:\\MyProject.gdb\\Communications",
"UPSTREAM",
"D:\\MyProject\\Default.gdb\\UN_Temp_Starting_Points",
null,
"Communications",//domain_network,
"Cable",//tier
"", //target tier
"", //subnetwork name
"", //shortest_path_network_attribute_name
"EXCLUDE_CONTAINERS",
"EXCLUDE_CONTENT",
"EXCLUDE_STRUCTURES",
"INCLUDE_BARRIERS",
"VALIDATE_CONSISTENCY",
null, //condition_barriers
null, //function_barriers
"BOTH_JUNCTIONS_AND_EDGES",//traversability_scope
null, //filter_barriers
null, //filter_function_barriers
"BOTH_JUNCTIONS_AND_EDGES",//filter_scope
"",//filter_bitset_network_attribute_name
"DO_NOT_FILTER",//filter_nearest
null, //nearest_count
"", //nearest_cost_network_attribute
null,//nearest_categories
null,//nearest_assets
null,//functions
null,//propagators
null,//output_assettypes
null,//output_conditions
//in_utility_network2,//output utility
"EXCLUDE_ISOLATED_FEATURES",
"DO_NOT_IGNORE_BARRIERS_AT_STARTING_POINTS",
"DO_NOT_INCLUDE_UP_TO_FIRST_SPATIAL_CONTAINER",
"CONNECTIVITY;SELECTION",//result_types
"NEW_SELECTION",
"CLEAR_ALL_PREVIOUS_TRACE_RESULTS",
"", //trace name
"Trace_Results_Aggregated_Points",
"Trace_Results_Aggregated_Lines",
"Trace_Results_Aggregated_Polygons",
"TRACE_INDETERMINATE_FLOW",
"DO_NOT_VALIDATE_LOCATABILITY",
"DO_NOT_USE_TRACE_CONFIGURATION",
"", //trace config name
"D:\\ArcGIS\\Projects\\MyProject\\connectivity.json",
"RUN_SYNCHRONOUSLY"
);