コード例 #1
0
        public static IEnumerable <T> GetUniqueColumnValues <T>(ICursor cursor, string columnName)
        {
            IDataStatistics dataStatistics = null;

            try
            {
                //获取null值
                T nullValue = default(T);
                dataStatistics        = new DataStatisticsClass();
                dataStatistics.Cursor = cursor;
                dataStatistics.Field  = columnName;
                IEnumerator enumerator = dataStatistics.UniqueValues;
                enumerator.Reset();
                while (enumerator.MoveNext())
                {
                    object currValue = enumerator.Current;
                    if (currValue == DBNull.Value || currValue == null)
                    {
                        yield return(nullValue);
                    }
                    else
                    {
                        yield return((T)Convert.ChangeType(currValue, typeof(T)));
                    }
                }
            }
            finally
            {
                AOUtil.ReleaseComObjectAllRefs(dataStatistics);
            }
        }
コード例 #2
0
ファイル: LayerFieldInfo.cs プロジェクト: Mengzuozhu/AeHelper
        /// <summary>
        /// 获取图层字段的唯一值
        /// </summary>
        /// <param name="layer">图层</param>
        /// <param name="fieldName">字段名称</param>
        /// <returns>唯一值</returns>
        public static List <string> GetLayerFieldUniqueValue(ILayer layer, string fieldName)
        {
            List <string>   value          = new List <string>();
            IDataStatistics dataStatistics = GetDataStatistics(layer, fieldName);

            if (dataStatistics == null)
            {
                return(value);
            }

            //枚举唯一值
            IEnumerator enumerator = dataStatistics.UniqueValues;

            enumerator.Reset();           //将游标重置到第一个成员前面
            while (enumerator.MoveNext()) //将游标的内部位置向前移动
            {
                object current = enumerator.Current;
                if (current != null)
                {
                    value.Add(current.ToString());
                }
            }

            return(value);
        }
コード例 #3
0
        private IElement method_3(IRow irow_0, IPageLayout ipageLayout_0)
        {
            ITable table = irow_0.Table;
            ElementsTableStruct struct2 = new ElementsTableStruct();
            object   obj2    = irow_0.get_Value(table.FindField(struct2.AttributesFieldName));
            IElement element = this.method_2(obj2);

            if (element is ITextElement)
            {
                string text = (element as ITextElement).Text;
                if (text[0] == '=')
                {
                    string[] strArray = text.Substring(1, text.Length - 1).Split(new char[] { '!' });
                    if (strArray[0] == "Field")
                    {
                        string   str3;
                        string   str4;
                        string   str2      = "";
                        string[] strArray2 = strArray[1].Split(new char[] { '.' });
                        if (strArray2.Length > 2)
                        {
                            str2 = strArray2[0];
                            str3 = strArray2[1].Substring(1, strArray2[0].Length - 2);
                            str4 = strArray2[2].Substring(1, strArray2[1].Length - 2);
                        }
                        else
                        {
                            str3 = strArray2[0].Substring(1, strArray2[0].Length - 2);
                            str4 = strArray2[1].Substring(1, strArray2[1].Length - 2);
                        }
                        string       str5        = "";
                        IQueryFilter queryFilter = null;
                        if (strArray.Length >= 3)
                        {
                            queryFilter = new QueryFilterClass();
                            string[] strArray3 = strArray[2].Split(new char[] { '#' });
                            int      index     = 0;
                            bool     flag      = true;
                            for (index = 0; index < strArray3.Length; index++)
                            {
                                if (flag)
                                {
                                    str5 = str5 + " " + strArray3[index];
                                }
                                else
                                {
                                    str5 = str5 + " " + this.hashtable_0[strArray3[index]].ToString();
                                }
                                flag = !flag;
                            }
                            queryFilter.WhereClause = str5;
                        }
                        try
                        {
                            ITable          table2     = ((irow_0.Table as IDataset).Workspace as IFeatureWorkspace).OpenTable(str3);
                            ICursor         o          = table2.Search(queryFilter, false);
                            IDataStatistics statistics = null;
                            statistics = new DataStatisticsClass
                            {
                                Field  = str4,
                                Cursor = o
                            };
                            IStatisticsResults results = statistics.Statistics;
                            string             str6    = str2;
                            switch (str6)
                            {
                            case null:
                                break;

                            case "SUM":
                                (element as ITextElement).Text = results.Sum.ToString();
                                goto Label_034E;

                            case "MAX":
                                (element as ITextElement).Text = results.Maximum.ToString();
                                goto Label_034E;

                            case "MIN":
                                (element as ITextElement).Text = results.Minimum.ToString();
                                goto Label_034E;

                            default:
                                if (str6 != "STD")
                                {
                                    if (str6 != "MEAN")
                                    {
                                        break;
                                    }
                                    (element as ITextElement).Text = results.Mean.ToString();
                                }
                                else
                                {
                                    (element as ITextElement).Text = results.StandardDeviation.ToString();
                                }
                                goto Label_034E;
                            }
                            IRow row = o.NextRow();
                            if (row != null)
                            {
                                try
                                {
                                    string str7 = row.get_Value(table2.FindField(str4)).ToString();
                                    (element as ITextElement).Text = str7;
                                }
                                catch
                                {
                                }
                            }
Label_034E:
                            ComReleaser.ReleaseCOMObject(o);
                        }
                        catch
                        {
                        }
                    }
                    else if (strArray[0] == "Param")
                    {
                        try
                        {
                            (element as ITextElement).Text = this.hashtable_0[strArray[1]].ToString();
                        }
                        catch
                        {
                        }
                    }
                }
            }
            if (element != null)
            {
                int       num3;
                double    num4;
                double    num5;
                IEnvelope envelope;
                object    obj3 = irow_0.get_Value(table.FindField(struct2.LocationFieldName)).ToString();
                if (obj3 is DBNull)
                {
                    return(element);
                }
                IPoint p = this.method_4(obj3.ToString(), ipageLayout_0, out num3, out num4, out num5);
                if (element is ITextElement)
                {
                    if ((element as IElementProperties).Type == "竖向")
                    {
                        string str8 = this.method_1((element as ITextElement).Text);
                        (element as ITextElement).Text = str8;
                    }
                    element.Geometry = p;
                    return(element);
                }
                if (element is IMapSurroundFrame)
                {
                    envelope = element.Geometry.Envelope;
                    envelope.CenterAt(p);
                    element.Geometry = envelope;
                    return(element);
                }
                envelope = element.Geometry.Envelope;
                envelope.CenterAt(p);
                element.Geometry = envelope;
            }
            return(element);
        }
コード例 #4
0
        /// <summary>
        /// 矢量数据叠加分类统计
        /// </summary>
        /// <param name="pSFeatClass">源要素类,必须为面要素类</param>
        /// <param name="zoneField">分区字段,整形或字符字段,该字段需要添加到统计结果表字段中</param>
        /// <param name="pTFeatClass">目标字段</param>
        /// <param name="FieldNames">统计字段列表,为数字字段</param>
        /// <param name="StatisticsTypes">
        /// 统计方法列表,和统计字段列表相对应
        /// 可用的统计方法字串如下:MIN, MAX, SUM, STD MEAN 最小值、最大值、总和、标准差, 平均值
        /// </param>
        public IList FeatureClassOverlapStatistics(ITable pSTable, IPolygon pPolygon, string[] FieldNames,
                                                   string[] StatisticsTypes)
        {
            IList arrayLists = new ArrayList();

            string[] str = new string[(int)FieldNames.Length];
            for (int i = 0; i < (int)FieldNames.Length; i++)
            {
                str[i] = "0";
            }
            ICursor         cursor = null;
            IDataStatistics dataStatisticsClass = null;
            ISpatialFilter  spatialFilterClass  = new SpatialFilter()
            {
                Geometry   = pPolygon,
                SpatialRel = esriSpatialRelEnum.esriSpatialRelContains
            };

            for (int j = 0; j < (int)FieldNames.Length; j++)
            {
                if (dataStatisticsClass != null)
                {
                    Marshal.ReleaseComObject(dataStatisticsClass);
                    dataStatisticsClass = null;
                }
                dataStatisticsClass = new DataStatistics()
                {
                    Field = FieldNames[j]
                };
                cursor = pSTable.Search(spatialFilterClass, true);
                dataStatisticsClass.Cursor = cursor;
                IStatisticsResults statistics = dataStatisticsClass.Statistics;
                if (statistics.Count > 0)
                {
                    double sum             = 0;
                    string statisticsTypes = StatisticsTypes[j];
                    if (statisticsTypes != null)
                    {
                        if (statisticsTypes == "SUM")
                        {
                            sum = statistics.Sum;
                        }
                        else if (statisticsTypes == "MAX")
                        {
                            sum = statistics.Maximum;
                        }
                        else if (statisticsTypes == "MIN")
                        {
                            sum = statistics.Minimum;
                        }
                        else if (statisticsTypes == "STD")
                        {
                            sum = statistics.StandardDeviation;
                        }
                        else if (statisticsTypes == "MEAN")
                        {
                            sum = statistics.Mean;
                        }
                    }
                    str[j] = sum.ToString();
                }
                Marshal.ReleaseComObject(cursor);
                cursor     = null;
                statistics = null;
            }
            arrayLists.Add(str);
            return(arrayLists);
        }
コード例 #5
0
        /// <summary>
        /// 矢量数据分区分类统计
        /// </summary>
        /// <param name="pSFeatClass">源要素类,必须为面要素类</param>
        /// <param name="zoneField">分区字段,整形或字符字段,该字段需要添加到统计结果表字段中</param>
        /// <param name="classField">分类统计字段,整形或字符字段</param>
        /// <param name="classFieldType">分类统计字段类型,0 -整形 1- 字符字段</param>///
        /// <param name="FieldNames">统计字段列表,为数字字段</param>
        /// <param name="StatisticsTypes">
        /// 统计方法列表,和统计字段列表相对应
        /// 可用的统计方法字串如下:MIN, MAX, SUM, STD 最小值、最大值、总和、标准差
        /// </param>
        public IList FeatureClassOverlapStatistics(ITable pTable, string classField, IPolygon pPolygon,
                                                   string[] FieldNames, string[] StatisticsTypes)
        {
            IList lists;
            IList arrayLists = new ArrayList();

            try
            {
                if (classField.Length <= 0)
                {
                    lists = this.FeatureClassOverlapStatistics(pTable, pPolygon, FieldNames, StatisticsTypes);
                    return(lists);
                }
                else
                {
                    IList         arrayLists1 = new ArrayList();
                    esriFieldType type        = pTable.Fields.Field[pTable.FindField(classField)].Type;
                    this.GetUniqueValues(pTable, classField, arrayLists1);
                    IDataStatistics dataStatisticsClass = null;
                    ISpatialFilter  spatialFilterClass  = new SpatialFilter();
                    string          str = "";
                    spatialFilterClass.Geometry   = pPolygon;
                    spatialFilterClass.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                    for (int i = 0; i < arrayLists1.Count; i++)
                    {
                        str = (type != esriFieldType.esriFieldTypeString
                            ? string.Concat(classField, " = ", arrayLists1[i].ToString())
                            : string.Concat(classField, " = '", arrayLists1[i].ToString(), "'"));
                        spatialFilterClass.WhereClause = str;
                        ICursor  cursor    = null;
                        string[] strArrays = new string[(int)FieldNames.Length + 1];
                        for (int j = 0; j < (int)FieldNames.Length; j++)
                        {
                            strArrays[j + 1] = "0";
                        }
                        strArrays[0] = arrayLists1[i].ToString();
                        for (int k = 0; k < (int)FieldNames.Length; k++)
                        {
                            cursor = pTable.Search(spatialFilterClass, true);
                            dataStatisticsClass = new DataStatistics()
                            {
                                Field  = FieldNames[k],
                                Cursor = cursor
                            };
                            IStatisticsResults statistics = dataStatisticsClass.Statistics;
                            if (statistics.Count > 0)
                            {
                                double sum             = 0;
                                string statisticsTypes = StatisticsTypes[k];
                                if (statisticsTypes != null)
                                {
                                    if (statisticsTypes == "SUM")
                                    {
                                        sum = statistics.Sum;
                                    }
                                    else if (statisticsTypes == "MAX")
                                    {
                                        sum = statistics.Maximum;
                                    }
                                    else if (statisticsTypes == "MIN")
                                    {
                                        sum = statistics.Minimum;
                                    }
                                    else if (statisticsTypes == "STD")
                                    {
                                        sum = statistics.StandardDeviation;
                                    }
                                    else if (statisticsTypes == "MEAN")
                                    {
                                        sum = statistics.Mean;
                                    }
                                }
                                strArrays[k + 1] = sum.ToString();
                            }
                            statistics = null;
                            Marshal.ReleaseComObject(cursor);
                            cursor = null;
                            Marshal.ReleaseComObject(dataStatisticsClass);
                            dataStatisticsClass = null;
                            GC.Collect();
                        }
                        arrayLists.Add(strArrays);
                    }
                    lists = arrayLists;
                    return(lists);
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
            }
            lists = null;
            return(lists);
        }
コード例 #6
0
 public SearchStatistics(IDataStatistics dataStatistics)
 {
     _dataStatistics = dataStatistics;
 }