Arcengine Statistical Method
Overview
Common statistical functions include unique field statistics, data ROW statistics, and data value sum statistics.
1. The basestatistics component is used to generate and report statistical results.
2. The ifrequencystatistics interface provides access requests to members who report frequency statistics.
3. The igeneratestatistics interface provides access to Members used to generate statistical results.
4. istatisticsresults provides access to members who report statistical results.
Accessible attributes include count, sum, maximum, minimum, meanm, standarddeviation (standard deviation)
The datastatistics component allows you to return statistical results and unique values of a single field. After the component is created, the data used for analysis is passed in as a cursor through the idatastatistics: cursor attribute. Note that the icursor object can only be used once. If you want to obtain multiple results, you should create a cursor again. Idatastatistics is the only interface in the data statistics component.
1. idatastatistics
Attribute
Cursor -- generate a statistical table using a cursor
Field -- the field to be counted
Uniquevaluecount -- total number of unique values in the statistical table
Uniquevalues -- unique value Enumeration
Statistics -- Istatisticsresults object, used to return statistics
2. istatisticsresults
Attribute
Count -- total number of values
Maximum -- maximum value
Mean-arithmetic mean
Minimum -- Minimum value
Standarddeviation -- Standard Deviation
Sum -- sum
Example: unique field statistics, Geodatabase does not provide keywords such as distinct for unique value query, only throughIdatastatistics: uniquevaluesMethod To obtain unique values
Public void idatastatistics_example (ifeatureclass featureclass)
{
Icursor cursor = (icursor) featureclass. Search (null, false );
Idatastatistics datastatistics = new datastatisticsclass ();
Datastatistics. Field = "pip_size ";
Datastatistics. cursor = cursor;
// Obtain the unique value
System. Collections. ienumerator enumerator = datastatistics. uniquevalues;
Enumerator. Reset ();
While (enumerator. movenext ())
{
Object myobject = enumerator. Current;
Console. writeline ("value-{0}", myobject. tostring ());
}
// Calculate the arithmetic mean value
Cursor = (icursor) featureclass. Search (null, false );
Datastatistics. cursor = cursor;
ESRI. ArcGIS. esrisystem. istatisticsresults statisticsresults = datastatistics. Statistics;
Console. writeline ("Mean Value-{0}", statisticsresults. Mean );
}
The Interface Description and examples show that the statistics are based on the statistics of numeric fields.
In addition, the query and Statistics interfaces include iquerydef, iqueryfilterdefinition, and itable. Example:
// Iquerydef example
Public void iquerydef_example (iworkspace workspace)
{
Ifeatureworkspace featureworkspace = (ifeatureworkspace) Workspace;
// Create query Definition
Iquerydef querydef = featureworkspace. createquerydef ();
// Provide List of tables to join
Querydef. Tables = "datesjoin, dudatest ";
// Retrieve the fields from all tables
Querydef. subfields = "SDE. datesjoin. dt_field = SDE. dudates. dt_field ";
// Set up join
Querydef. whereclause = "datesjoin. dt_field = dudates. dt_field ";
// Create featuredataset. Note the use of. openfeaturequery.
// The name "myjoin" is the name of the restult of the query def and
// Is used in place of a feature class name.
Ifeaturedataset featuredataset = featureworkspace. openfeaturequery ("myjoin", querydef );
// Open layer to test against
Ifeatureclasscontainer featureclasscontainer = (ifeatureclasscontainer) featuredataset;
Ifeatureclass featureclass = featureclasscontainer. get_classbyname ("myjoin ");
}
// Iqueryfilterdefinition postfixclause example
Public void iqueryfilterdefinition_postfixclause_example (ifeatureclass featureclass)
{
// This function uses the postfixclause property to append an order by clause to the query.
Iqueryfilter queryfilter = new queryfilterclass ();
Queryfilter. subfields = "fullname ";
Queryfilter. whereclause = "objectid> 10 ";
Iqueryfilterdefinition queryfilterdefinition = (iqueryfilterdefinition) queryfilter;
Queryfilterdefinition. postfixclause = "order by fullname ";
Ifeaturecursor featurecursor = featureclass. Search (queryfilter, true );
Int fieldindex = featurecursor. findfield ("fullname ");
Ifeature feature = featurecursor. nextfeature ();
While (feature! = NULL)
{
Console. writeline ("the value of the {0} field is {1)", featurecursor. Fields. get_field (fieldindex). Name, feature. get_value (fieldindex ));
Feature = featurecursor. nextfeature ();
}
}
// Itable example
Public void itable_example (ifeatureclass featureclass)
{
Itable ptable = featureclassas itable;
Console. writeline ("the row count is: {0}", ptable. rowcount. tostring ());
}