ArcGis 统计方法

from:http://blog.sina.com.cn/s/blog_4177d50b0100fjbg.html

 

概述

     一般常用的统计功能例如:唯一字段统计、数据行数统计、数据值求和统计等。

    1、基础统计(BaseStatistics)组件用来生成和报告统计结果。

    2、IFrequencyStatistics接口提供对用来报告频率统计的成员的访 问。

    3、IGenerateStatistics接口提供对用来生成统计结果的成员的访问。

    4、IStatisticsResults提供对用来报告统计结果的成员的访问。

    可访问的属性有Count,Sum,Maximum,Minimum,Meanm,StandardDeviation标准差)

     DataStatistics组件允许返回统计结果及单个字段的唯一值。组件创建后,用来分析的数据通过IDataStatistics::Cursor属性,以光标形式的传入。注意ICursor的对象只能使用一次,如果要获取多个结果,应当再次创建光标。IDataStatistics是数据统计组件中唯一的接口

1、IDataStatistics

属性

Cursor--通过游标来生成统计表

Field--要统计的字段

UniquueCount--统计表中唯一值总数

Uniquues--唯一值枚举

Statistics-- IStatisticsResults对象,用于返回统计信息

2、IStatisticsResults

属性

Count--值总数

Maximum --最大值

Mean--算术平均值

Minimum--最小值

StandardDeviation--标准差

Sum--求和

 

示例:唯一字段统计,GeoDatabase没有提供DISTINCT这样的关键字进行唯一值查询,只有通过IDataStatistics::Uniquues方式来获取唯一值

 

 

public void IDataStatistics_ExampleIFeatureClass featureClass)
    {
        ICursor cursor = ICursor)featureClass.Searchnull, false);

        IDataStatistics dataStatistics = new DataStatisticsClass);
        dataStatistics.Field = “PIP_SIZE”;

        dataStatistics.Cursor = cursor;

        //求唯一值

        System.Collections.IEnumerator enumerator = dataStatistics.Uniquues;
        enumerator.Reset);

        while enumerator.MoveNext))
        {
            object myObject = enumerator.Current;
            Console.WriteLine”Value – {0}”, myObject.ToString));

        }

       //求算术平均值

        cursor = ICursor)featureClass.Searchnull, false);
        dataStatistics.Cursor = cursor;
        ESRI.ArcGIS.esriSystem.IStatisticsResults statisticsResults = dataStatistics.Statistics;
        Console.WriteLine”mean value – {0}”, statisticsResults.Mean);

    }

 

    通过接口说明和示例可以看出,统计信息是基于数字字段的统计。

 

     另外,关于查询与统计接口,还有IQueryDef、IQueryFilterDefinition、ITable等。例子如下:

 

 //IQueryDef Example

public void IQueryDef_ExampleIWorkspace 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_ExampleIFeatureClass 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.SearchqueryFilter, 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_FieldfieldIndex).Name, feature.get_ValuefieldIndex));
            feature = featureCursor.NextFeature);
        }
    }

 

 

//ITable Example

Public Void ITable_ExampleIFeatureClass featureClass)

{

 

    ITable pTable = featureClassas ITable;

    Console.WriteLine”The Row Count is:{0}”,pTable.RowCount.Tostring));

 

}

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注