You provide a nice example of how to set up calculatestatistics here:
ProConcepts Geodatabase · Esri/arcgis-pro-sdk Wiki · GitHub
However, most folks (me) are interested in the actual values produced.
Can someone lead me in a direction to get an actual value from IReadOnlyList<TableStatisticsResult>?
I calculated a SUM of a field, but want to provide the value to a new variable for further calculation...
Thank You.
Hi Brian,
Try this:
<SPAN class="keyword token">var</SPAN> <SPAN class="keyword token">value</SPAN> <SPAN class="operator token">=</SPAN> vlsStatsResult<SPAN class="punctuation token">.</SPAN><SPAN class="token function">First</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>StatisticsResults<SPAN class="punctuation token">.</SPAN><SPAN class="token function">First</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>Max<SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
Thanks
Uma
Hi Mike,
There is no direct way to do this. The best solution at this point is to create a temporary table from your selection using geoprocessing tools and use that to run Table.CalculateStatistics().
(I already answered in another thread, but wanted to duplicate the answer here in case others see it)
--Rich
Coda to the original question:
How can I perform Table operations like .CalculateStatistics upon a FeatureLayer.GetSelection()?
i.e., converting a featurelayer selection (from user) into a temporary table so I can .CalculateStatistics.
Thanks, Uma.
".StatisticsResults.First().Max;" was all I needed to get moving again on my code.
Thanks, Rich for the expanded clarification.
To answer Mike's original question, I've expanded the snippet he posted to extract the calculation results. Here is the code:
// Calculate StatisticsIReadOnlyList<TableStatisticsResult> tableStatisticsResults = countryFeatureClass.CalculateStatistics(tableStatisticsDescription);
foreach(TableStatisticsResult tableStatisticsResult in tableStatisticsResults){ // Get the Region name // If multiple fields had been passed into TableStatisticsDescription.GroupBy, there
// would be multiple values in TableStatisticsResult.GroupBy string regionName = tableStatisticsResult.GroupBy.First().Value.ToString();
// Get the statistics results for the Population_1990 field StatisticsResult pop1990Statistics = tableStatisticsResult.StatisticsResults[0]; double population1990Sum = pop1990Statistics.Sum; double population1990Average = pop1990Statistics.Average;
// Get the statistics results for the Population_2000 field StatisticsResult pop2000Statistics = tableStatisticsResult.StatisticsResults[1]; double population2000Sum = pop2000Statistics.Sum; double population2000Average = pop2000Statistics.Average;
// Do something with the results here...
}
I hope this helps.
Great! Thanks Uma.
Yes, I have exactly the same question. I think I've been able to calculate the MAX value of a certain field, but I have no idea of how to actually get the value out of the TableStatisticsResult.
Any help is appreciated.
FeatureClass vlsFC <SPAN class="operator token">=</SPAN> vlsLayer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetFeatureClass</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> FeatureClassDefinition fcd <SPAN class="operator token">=</SPAN> vlsFC<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetDefinition</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> Field fldVLS_NO_1 <SPAN class="operator token">=</SPAN> fcd<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetFields</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">First</SPAN><SPAN class="punctuation token">(</SPAN>x <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> x<SPAN class="punctuation token">.</SPAN>Name<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Equals</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"VLS_NO_1"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> StatisticsDescription vlsMaxDesc <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">StatisticsDescription</SPAN><SPAN class="punctuation token">(</SPAN>fldVLS_NO_1<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">List</SPAN><SPAN class="operator token"><</SPAN>StatisticsFunction<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> StatisticsFunction<SPAN class="punctuation token">.</SPAN>Max <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> TableStatisticsDescription tsd <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">TableStatisticsDescription</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">List</SPAN><SPAN class="operator token"><</SPAN>StatisticsDescription<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> vlsMaxDesc <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> IReadOnlyList<SPAN class="operator token"><</SPAN>TableStatisticsResult<SPAN class="operator token">></SPAN> vlsStatsResult <SPAN class="operator token">=</SPAN> vlsFC<SPAN class="punctuation token">.</SPAN><SPAN class="token function">CalculateStatistics</SPAN><SPAN class="punctuation token">(</SPAN>tsd<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//This does not work</SPAN> ArcGIS<SPAN class="punctuation token">.</SPAN>Desktop<SPAN class="punctuation token">.</SPAN>Framework<SPAN class="punctuation token">.</SPAN>Dialogs<SPAN class="punctuation token">.</SPAN>MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Max VLS is "</SPAN> <SPAN class="operator token">+</SPAN> vlsStatsResult<SPAN class="punctuation token">.</SPAN>Max<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.