/// <summary>
        /// 要素排序
        /// </summary>
        /// <param name="pFeatureClass">要排序的要素类</param>
        /// <param name="columName">Name of the colum.</param>
        private void SortFeatures(IFeatureClass pFeatureClass, string columName)
        {
            ITableSort pTableSort = new TableSortClass();
            IFields    pFields    = pFeatureClass.Fields;
            int        index      = pFields.FindFieldByAliasName(columName);
            IField     pField     = pFields.get_Field(index);

            pTableSort.Fields = pField.Name;

            switch (_up)
            {
            case true:
                pTableSort.set_Ascending(pField.Name, true);
                _up = false;
                break;

            case false:
                pTableSort.set_Ascending(pField.Name, false);
                _up = true;
                break;
            }
            pTableSort.set_CaseSensitive(pField.Name, true);
            pTableSort.Table = pFeatureClass as ITable;
            pTableSort.Sort(null);
            ICursor pCursor = pTableSort.Rows;

            _pTs = pTableSort;
            RefreshTable();
        }
Beispiel #2
0
        /// <summary>
        /// 数据排序
        /// </summary>
        /// <param name="pFeatureClass"></param>
        //排序函数
        private void SortFeatures(IFeatureClass pFeatureClass, IFeatureLayer _pLayer)
        {
            ITableSort pTableSort = new TableSortClass();
            IFields    pFields    = pFeatureClass.Fields;
            IField     pField     = pFields.get_Field(col_index);

            col_index         = 0;
            pTableSort.Fields = pField.Name;

            if (up)
            {
                pTableSort.set_Ascending(pField.Name, true);
            }
            else
            {
                pTableSort.set_Ascending(pField.Name, false);
            }
            pTableSort.set_CaseSensitive(pField.Name, true);
            pTableSort.Table = pFeatureClass as ITable;
            pTableSort.Sort(null);
            ICursor pCursor = pTableSort.Rows;

            pTs = pTableSort;
            RefreshTable(_pLayer, pFeatureClass, dataGridView1, pField.Name, pCursor);
        }
Beispiel #3
0
        /// <summary>
        /// 数据排序
        /// </summary>
        /// <param name="pFeatureClass"></param>
        private void SortFeatures(IFeatureClass pFeatureClass)
        {
            ITableSort pTableSort = new TableSortClass();
            IFields    pFields    = pFeatureClass.Fields;
            IField     pField     = pFields.get_Field(col_index);

            pTableSort.Fields = pField.Name;
            pTableSort.set_Ascending(pField.Name, up);
            pTableSort.set_CaseSensitive(pField.Name, true);
            pTableSort.Table = pFeatureClass as ITable;
            pTableSort.Sort(null);
            pFCuror = (IFeatureCursor)pTableSort.Rows;
            pTs     = pTableSort;
            RefreshDataGridViewDataSource(gdvAttribute, GetAttributeTable(pFClass, pFCuror));
        }
        /// <summary>
        /// 获得当前字段的唯一值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonGetValue_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.listBoxFields.SelectedIndex == -1)
                {
                    return;
                }

                string currentFieldName = this.listBoxFields.Text;//当前字段名
                string currentLayerName = this.comboBoxLayers.Text;
                this.pEnumLayer.Reset();
                for (this.pLayer = this.pEnumLayer.Next(); this.pLayer != null; this.pLayer = this.pEnumLayer.Next())
                {
                    if (this.pLayer.Name == currentLayerName)
                    {
                        break;
                    }
                }
                this.pLayerFields = this.pLayer as ILayerFields;
                IField        pField     = this.pLayerFields.get_Field(this.pLayerFields.FindField(currentFieldName));
                esriFieldType pFieldType = pField.Type;

                //对Table中当前字段进行排序,把结果赋给Cursor
                ITable     pTable     = this.pLayer as ITable;
                ITableSort pTableSort = new TableSortClass();
                pTableSort.Table  = pTable;
                pTableSort.Fields = currentFieldName;
                pTableSort.set_Ascending(currentFieldName, true);
                pTableSort.set_CaseSensitive(currentFieldName, true);
                pTableSort.Sort(null);//排序
                ICursor pCursor = pTableSort.Rows;

                //字段统计
                IDataStatistics pDataStatistics = new DataStatisticsClass();
                pDataStatistics.Cursor = pCursor;
                pDataStatistics.Field  = currentFieldName;
                System.Collections.IEnumerator pEnumeratorUniqueValues = pDataStatistics.UniqueValues; //唯一值枚举
                int uniqueValueCount = pDataStatistics.UniqueValueCount;                               //唯一值的个数

                this.listBoxValues.Items.Clear();
                string currentValue = null;
                pEnumeratorUniqueValues.Reset();
                if (pFieldType == esriFieldType.esriFieldTypeString)
                {
                    while (pEnumeratorUniqueValues.MoveNext())
                    {
                        currentValue = pEnumeratorUniqueValues.Current.ToString();
                        this.listBoxValues.Items.Add("'" + currentValue + "'");
                    }
                }
                else
                {
                    while (pEnumeratorUniqueValues.MoveNext())
                    {
                        currentValue = pEnumeratorUniqueValues.Current.ToString();
                        this.listBoxValues.Items.Add(currentValue);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #5
0
        private void btnShowAllValue_Click(object sender, EventArgs e)
        {
            if (cmbFields.Text == "")
            {
                MessageBox.Show("请选择字段名", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            listBoxValue.Items.Clear();
            IFeatureLayer pFeatureLayer;

            pFeatureLayer = (IFeatureLayer)pMap.get_Layer(iLayerIndex);

            IFeatureCursor pFeatureCursor;

            pFeatureCursor = pFeatureLayer.FeatureClass.Search(null, false);

            IFeature pFeature;

            pFeature = pFeatureCursor.NextFeature();



            //对Table中当前字段进行排序,把结果赋给Cursor

            ITable pTable = pFeatureLayer as ITable;

            ITableSort pTableSort = new TableSortClass();

            pTableSort.Table = pTable;

            pTableSort.Fields = cmbFields.Text;

            pTableSort.set_Ascending(cmbFields.Text, true);

            pTableSort.set_CaseSensitive(cmbFields.Text, true);

            pTableSort.Sort(null);

            ICursor pCursor = pTableSort.Rows;


            //数值统计

            IDataStatistics pData = new DataStatisticsClass();

            pData.Cursor = pCursor;

            pData.Field = cmbFields.Text;



            System.Collections.IEnumerator pEnumeratorUniqueValues = pData.UniqueValues; //唯一值枚举
            int uniqueValueCount = pData.UniqueValueCount;                               //唯一值的个数

            this.listBoxValue.Items.Clear();

            string fldValue = null;

            pEnumeratorUniqueValues.Reset();

            ILayerFields pFields = pFeatureLayer as ILayerFields;

            if (pFields.get_Field(pFields.FindField(cmbFields.Text)).Type == esriFieldType.esriFieldTypeString)
            {
                while (pEnumeratorUniqueValues.MoveNext())
                {
                    fldValue = pEnumeratorUniqueValues.Current.ToString();
                    this.listBoxValue.Items.Add("'" + fldValue + "'");
                }
            }
            else if (cmbFields.Text == "shape")
            {
                fldValue = Convert.ToString(pFeature.Shape.GeometryType);
                this.listBoxValue.Items.Add(fldValue);
            }
            else
            {
                while (pEnumeratorUniqueValues.MoveNext())
                {
                    fldValue = pEnumeratorUniqueValues.Current.ToString();
                    this.listBoxValue.Items.Add(fldValue);
                }
            }



            /* while(pFeature!=null)
             * {
             *   string fldValue;
             *   if (cmbFields.Text == "Shape")
             *   {
             *       fldValue = Convert.ToString(pFeature.Shape.GeometryType);
             *   }
             *   else
             *       fldValue = Convert.ToString(pFeature.get_Value(iFieldIndex));
             *
             *   listBoxValue.Items.Add(fldValue);
             *   pFeature = pFeatureCursor.NextFeature();
             * } */
        }
Beispiel #6
0
        private void GetAttributeVale()
        {
            try
            {
                if (this.listBoxField.SelectedIndex == -1)
                {
                    return;
                }

                string currentFieldName = this.listBoxField.Text;//当前字段名
                string currentLayerName = this.cboLayer.Text;
                this.pEnumLayer.Reset();
                for (this.pLayer = this.pEnumLayer.Next(); this.pLayer != null; this.pLayer = this.pEnumLayer.Next())
                {
                    if (this.pLayer.Name == currentLayerName)
                    {
                        break;
                    }
                }
                this.pLayerFields = this.pLayer as ILayerFields;
                IField        pField     = this.pLayerFields.get_Field(this.pLayerFields.FindField(currentFieldName));
                esriFieldType pFieldType = pField.Type;

                //对Table中当前字段进行排序,把结果赋给Cursor
                ITable     pTable     = this.pLayer as ITable;
                ITableSort pTableSort = new TableSortClass();
                pTableSort.Table  = pTable;
                pTableSort.Fields = currentFieldName;
                pTableSort.set_Ascending(currentFieldName, true);
                pTableSort.set_CaseSensitive(currentFieldName, true);
                pTableSort.Sort(null);//排序
                ICursor pCursor = pTableSort.Rows;
                //IRow pRow = pCursor.NextRow();
                //int nSize = 0;
                //while (pRow != null)
                //{
                //    nSize++;
                //    pRow = pCursor.NextRow();
                //}
                //DevComponents.DotNetBar.MessageBox.Show(nSize.ToString());
                //return;

                //字段统计
                IDataStatistics pDataStatistics = new DataStatisticsClass();
                pDataStatistics.Cursor = pCursor;
                pDataStatistics.Field  = currentFieldName;
                System.Collections.IEnumerator pEnumeratorUniqueValues = pDataStatistics.UniqueValues; //唯一值枚举
                int uniqueValueCount = pDataStatistics.UniqueValueCount;                               //唯一值的个数

                this.listBoxValue.Items.Clear();
                string currentValue = null;
                pEnumeratorUniqueValues.Reset();
                if (pFieldType == esriFieldType.esriFieldTypeString)
                {
                    while (pEnumeratorUniqueValues.MoveNext())
                    {
                        currentValue = pEnumeratorUniqueValues.Current.ToString();
                        this.listBoxValue.Items.Add("'" + currentValue + "'");
                    }
                }
                else
                {
                    while (pEnumeratorUniqueValues.MoveNext())
                    {
                        currentValue = pEnumeratorUniqueValues.Current.ToString();
                        this.listBoxValue.Items.Add(currentValue);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 数据排序
        /// </summary>
        /// <param name="pFeatureClass"></param>
        private void SortFeatures(IFeatureClass pFeatureClass)
        {
            ITableSort pTableSort = new TableSortClass();
            IFields pFields = pFeatureClass.Fields;
            IField pField = pFields.get_Field(col_index);

            pTableSort.Fields = pField.Name;
            pTableSort.set_Ascending(pField.Name, up); 
            pTableSort.set_CaseSensitive(pField.Name, true);
            pTableSort.Table = pFeatureClass as ITable;
            pTableSort.Sort(null);
            pFCuror = (IFeatureCursor)pTableSort.Rows;
            pTs = pTableSort;
            RefreshDataGridViewDataSource(gdvAttribute, GetAttributeTable(pFClass, pFCuror));
        }
Beispiel #8
0
        /// <summary>
        /// 获得当前字段的唯一值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonGetValue_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.listBoxFields.SelectedIndex == -1) return;

                string currentFieldName = this.listBoxFields.Text;//当前字段名
                string currentLayerName=this.comboBoxLayers.Text;
                this.pEnumLayer.Reset();
                for (this.pLayer = this.pEnumLayer.Next(); this.pLayer != null; this.pLayer = this.pEnumLayer.Next())
                {
                    if (this.pLayer.Name == currentLayerName) break;
                }
                this.pLayerFields = this.pLayer as ILayerFields;
                IField pField = this.pLayerFields.get_Field(this.pLayerFields.FindField(currentFieldName));
                esriFieldType pFieldType = pField.Type;

                //对Table中当前字段进行排序,把结果赋给Cursor
                ITable pTable = this.pLayer as ITable;
                ITableSort pTableSort = new TableSortClass();
                pTableSort.Table = pTable;
                pTableSort.Fields = currentFieldName;
                pTableSort.set_Ascending(currentFieldName, true);
                pTableSort.set_CaseSensitive(currentFieldName, true);
                pTableSort.Sort(null);//排序
                ICursor pCursor = pTableSort.Rows;

                //字段统计
                IDataStatistics pDataStatistics = new DataStatisticsClass();
                pDataStatistics.Cursor = pCursor;
                pDataStatistics.Field = currentFieldName;
                System.Collections.IEnumerator pEnumeratorUniqueValues = pDataStatistics.UniqueValues;//唯一值枚举
                int uniqueValueCount = pDataStatistics.UniqueValueCount;//唯一值的个数

                this.listBoxValues.Items.Clear();
                string currentValue = null;
                pEnumeratorUniqueValues.Reset();
                if (pFieldType == esriFieldType.esriFieldTypeString)
                {
                    while (pEnumeratorUniqueValues.MoveNext())
                    {
                        currentValue = pEnumeratorUniqueValues.Current.ToString();
                        this.listBoxValues.Items.Add("'" + currentValue + "'");
                    }
                }
                else
                {
                    while (pEnumeratorUniqueValues.MoveNext())
                    {
                        currentValue = pEnumeratorUniqueValues.Current.ToString();
                        this.listBoxValues.Items.Add(currentValue);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #9
0
        /// <summary>
        /// 按下"添加所有值"按钮后,让table按当前字段的值进行排序,并把信息添加到listView里面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUniValueAddAllValues_Click(object sender, EventArgs e)
        {
            try
            {
                string currentFieldName = this.cbbUniValueField.Text;//当前字段名

                string currentFieldType = this.lsvFields.FindItemWithText(currentFieldName).SubItems[2].Text;//当前字段类型
                bool currentTypeIsNumeric = false;//判断当前字段类型是否为数字类型
                if (currentFieldType == "Short Integer" || currentFieldType == "Long Integer" || currentFieldType == "Float" || currentFieldType == "Double")
                {
                    currentTypeIsNumeric = true;
                }

                this.lsvUniqueValue.Items.Clear();

                //对Table中当前字段进行排序,把结果赋给Cursor
                ITable pTable = this.pLayer as ITable;
                ITableSort pTableSort = new TableSortClass();
                pTableSort.Table = pTable;
                pTableSort.Fields = currentFieldName;
                pTableSort.set_Ascending(currentFieldName, true);
                pTableSort.set_CaseSensitive(currentFieldName, true);
                pTableSort.Sort(null);//排序
                ICursor pCursor = pTableSort.Rows;

                //字段统计
                IDataStatistics pDataStatistics = new DataStatisticsClass();
                pDataStatistics.Cursor = pCursor;
                pDataStatistics.Field = currentFieldName;
                System.Collections.IEnumerator pEnumeratorUniqueValues = pDataStatistics.UniqueValues;//唯一值枚举
                int uniqueValueCount = pDataStatistics.UniqueValueCount;//唯一值的个数

                //table中当前字段有值(不为null)的row的个数,并把信息添加到listView的第一行
                 IQueryFilter pQueryFilter = new QueryFilterClass();
                pQueryFilter.AddField(currentFieldName);
                int valueSum = pTable.RowCount(pQueryFilter);
                this.lsvUniqueValue.Items.Add(currentFieldName);
                this.lsvUniqueValue.Items[0].SubItems.Add(currentFieldName);
                this.lsvUniqueValue.Items[0].SubItems.Add(valueSum.ToString());

                //循环把信息添加到listView里
                int i = 1;//注意!是从1开始,因为第一行已经被占用
                string currentValue = null;//指示当前的值
                //IDataStatistics pUniValueStatistics = new DataStatisticsClass();
                int currentValueCount;
                for (pEnumeratorUniqueValues.Reset(); pEnumeratorUniqueValues.MoveNext(); i++)
                {
                    currentValue = pEnumeratorUniqueValues.Current.ToString();//当前值
                    this.lsvUniqueValue.Items.Add(currentValue);
                    this.lsvUniqueValue.Items[i].SubItems.Add(currentValue);
                    //需要这个if的原因是SQL语句中数字和非数字的写法不一样
                    if (currentTypeIsNumeric)
                    {
                        pQueryFilter.WhereClause = "\"" + currentFieldName + "\"" + " = " + currentValue;
                    }
                    else
                    {
                        pQueryFilter.WhereClause = "\"" + currentFieldName + "\"" + " = " + "'" + currentValue + "'";
                    }
                    currentValueCount = pTable.RowCount(pQueryFilter);//table中该字段是当前值的row的个数
                    this.lsvUniqueValue.Items[i].SubItems.Add(currentValueCount.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void btnShowAllValue_Click(object sender, EventArgs e)
        {
            if (cmbFields.Text=="")
            {
                MessageBox.Show("��ѡ���ֶ���", "��ʾ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            listBoxValue.Items.Clear();
            IFeatureLayer pFeatureLayer;
            pFeatureLayer = (IFeatureLayer)pMap.get_Layer(iLayerIndex);

            IFeatureCursor pFeatureCursor;
            pFeatureCursor = pFeatureLayer.FeatureClass.Search(null, false);

            IFeature pFeature;
            pFeature = pFeatureCursor.NextFeature();

            //��Table�е�ǰ�ֶν�������,�ѽ������Cursor

            ITable pTable = pFeatureLayer as ITable;

            ITableSort pTableSort = new TableSortClass();

            pTableSort.Table = pTable;

            pTableSort.Fields = cmbFields.Text;

            pTableSort.set_Ascending(cmbFields.Text, true);

            pTableSort.set_CaseSensitive(cmbFields.Text, true);

            pTableSort.Sort(null);

            ICursor pCursor = pTableSort.Rows;

            //��ֵͳ��

            IDataStatistics pData = new DataStatisticsClass();

            pData.Cursor = pCursor;

            pData.Field = cmbFields.Text;

            System.Collections.IEnumerator pEnumeratorUniqueValues = pData.UniqueValues;//Ψһֵö��
            int uniqueValueCount = pData.UniqueValueCount;//Ψһֵ�ĸ���

            this.listBoxValue.Items.Clear();

            string fldValue = null;

            pEnumeratorUniqueValues.Reset();

            ILayerFields pFields = pFeatureLayer as ILayerFields;

            if (pFields.get_Field(pFields.FindField(cmbFields.Text)).Type == esriFieldType.esriFieldTypeString)
            {
                while (pEnumeratorUniqueValues.MoveNext())
                {
                    fldValue = pEnumeratorUniqueValues.Current.ToString();
                    this.listBoxValue.Items.Add("'" + fldValue + "'");

                }
            }
                 else if(cmbFields .Text =="shape" )
            {
                fldValue = Convert.ToString(pFeature.Shape.GeometryType);
                this.listBoxValue.Items.Add(fldValue);
            }
            else
            {
                while (pEnumeratorUniqueValues.MoveNext())
                {
                    fldValue = pEnumeratorUniqueValues.Current.ToString();
                    this.listBoxValue.Items.Add(fldValue);
                }
            }

               /* while(pFeature!=null)
            {
                string fldValue;
                if (cmbFields.Text == "Shape")
                {
                    fldValue = Convert.ToString(pFeature.Shape.GeometryType);
                }
                else
                    fldValue = Convert.ToString(pFeature.get_Value(iFieldIndex));

                listBoxValue.Items.Add(fldValue);
                pFeature = pFeatureCursor.NextFeature();
            } */
        }
Beispiel #11
0
        /// <summary>
        /// 按下"添加所有值"按钮后,让table按当前字段的值进行排序,并把信息添加到listView里面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUniValueAddAllValues_Click(object sender, EventArgs e)
        {
            try
            {
                string currentFieldName = this.cbbUniValueField.Text;                                             //当前字段名

                string currentFieldType     = this.lsvFields.FindItemWithText(currentFieldName).SubItems[2].Text; //当前字段类型
                bool   currentTypeIsNumeric = false;                                                              //判断当前字段类型是否为数字类型
                if (currentFieldType == "Short Integer" || currentFieldType == "Long Integer" || currentFieldType == "Float" || currentFieldType == "Double")
                {
                    currentTypeIsNumeric = true;
                }

                this.lsvUniqueValue.Items.Clear();

                //对Table中当前字段进行排序,把结果赋给Cursor
                ITable     pTable     = this.pLayer as ITable;
                ITableSort pTableSort = new TableSortClass();
                pTableSort.Table  = pTable;
                pTableSort.Fields = currentFieldName;
                pTableSort.set_Ascending(currentFieldName, true);
                pTableSort.set_CaseSensitive(currentFieldName, true);
                pTableSort.Sort(null);//排序
                ICursor pCursor = pTableSort.Rows;

                //字段统计
                IDataStatistics pDataStatistics = new DataStatisticsClass();
                pDataStatistics.Cursor = pCursor;
                pDataStatistics.Field  = currentFieldName;
                System.Collections.IEnumerator pEnumeratorUniqueValues = pDataStatistics.UniqueValues; //唯一值枚举
                int uniqueValueCount = pDataStatistics.UniqueValueCount;                               //唯一值的个数

                //table中当前字段有值(不为null)的row的个数,并把信息添加到listView的第一行
                IQueryFilter pQueryFilter = new QueryFilterClass();
                pQueryFilter.AddField(currentFieldName);
                int valueSum = pTable.RowCount(pQueryFilter);
                this.lsvUniqueValue.Items.Add(currentFieldName);
                this.lsvUniqueValue.Items[0].SubItems.Add(currentFieldName);
                this.lsvUniqueValue.Items[0].SubItems.Add(valueSum.ToString());

                //循环把信息添加到listView里
                int    i            = 1;    //注意!是从1开始,因为第一行已经被占用
                string currentValue = null; //指示当前的值
                //IDataStatistics pUniValueStatistics = new DataStatisticsClass();
                int currentValueCount;
                for (pEnumeratorUniqueValues.Reset(); pEnumeratorUniqueValues.MoveNext(); i++)
                {
                    currentValue = pEnumeratorUniqueValues.Current.ToString();//当前值
                    this.lsvUniqueValue.Items.Add(currentValue);
                    this.lsvUniqueValue.Items[i].SubItems.Add(currentValue);
                    //需要这个if的原因是SQL语句中数字和非数字的写法不一样
                    if (currentTypeIsNumeric)
                    {
                        pQueryFilter.WhereClause = "\"" + currentFieldName + "\"" + " = " + currentValue;
                    }
                    else
                    {
                        pQueryFilter.WhereClause = "\"" + currentFieldName + "\"" + " = " + "'" + currentValue + "'";
                    }
                    currentValueCount = pTable.RowCount(pQueryFilter);//table中该字段是当前值的row的个数
                    this.lsvUniqueValue.Items[i].SubItems.Add(currentValueCount.ToString());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }