給ArcMap定製一個排序命令

來源:互聯網
上載者:User
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.esriSystem;
namespace TableSort
{
    public partial class Sort : Form
    {
        private ITable pTable;
        IMap pMap;
        public Sort(IMap _pMap)
        {
            InitializeComponent();
            this.pMap = _pMap;
        }
        private void Sort_Load(object sender, EventArgs e)
        {
            IDataset pDataset = null;
            ITable plTable=null ;
            ITableCollection pTableCollection = pMap as ITableCollection;
            for (int i = 0; i < pTableCollection.TableCount; i++)
            {
                plTable = pTableCollection.get_Table(i);
                pDataset = plTable as IDataset;
                comboBox1.Items.Add(pDataset.Name);
               
            }

           comboBox1.Text = comboBox1.Items[0].ToString();
        
           FieldName(comboBox2, FindTable (pMap as ITableCollection  ,comboBox1.Text ));
           comboBox3.Items.Add("升序");
           comboBox3.Items.Add("降序");
           comboBox3.Text = comboBox3.Items[0].ToString();
        }
        private void FieldName(ComboBox _pComBox, ITable _pTable)
        {
            IFields pTableFields = _pTable.Fields;
            for (int i = 0; i < pTableFields.FieldCount; i++)
            {
                if ( pTableFields.get_Field(i).Type != esriFieldType.esriFieldTypeOID)
                {
                    _pComBox.Items.Add(pTableFields.get_Field(i).Name);
                }
            }
           _pComBox.Text = _pComBox.Items[0].ToString();
        }
        private ITable FindTable(ITableCollection _pTabbleCollection, string _Name)
        {
            ITable plTable = null; ;
            IDataset plDataset;
            for (int i = 0; i < _pTabbleCollection .TableCount ;i++)
            {
               
                plDataset = _pTabbleCollection.get_Table(i) as IDataset;
                if (plDataset.Name == _Name.Trim ())
                {
                    plTable = _pTabbleCollection.get_Table(i);
                    break;
                }
            }
            return plTable;
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            FieldName(comboBox2, FindTable(pMap as ITableCollection, comboBox1.Text));
        }
        private void bOK_Click(object sender, EventArgs e)
        {
            pTable = FindTable(pMap as ITableCollection, comboBox1.Text);
            ITableSort plTalbeSort = new TableSortClass();
            plTalbeSort.Table = pTable;
            plTalbeSort.Fields = comboBox2.Text.Trim();
            if (comboBox3.Text.Trim () == "降序")
            {
                plTalbeSort.set_Ascending(comboBox2.Text, false );
            }
            else
            {
                plTalbeSort.set_Ascending(comboBox2.Text, true);
            }
            plTalbeSort.Sort(null);            
            
            ICursor plSortCursor = plTalbeSort.Rows;
            IRow pSortRow = plSortCursor .NextRow ();
            IDataset plSortDataset = pTable as IDataset;
            IFeatureWorkspace plFWS = plSortDataset.Workspace as IFeatureWorkspace;
           ITable plStable= plFWS.CreateTable("NewSort", pTable.Fields, null, null, null);

           while (pSortRow != null)
           {
               IRow pRow = plStable.CreateRow();
               for (int i=0;i <pRow .Fields .FieldCount;i++ )
               {
                   if (pRow .Fields .get_Field (i).Type !=esriFieldType .esriFieldTypeOID)
                   {
                      pRow.set_Value (i,pSortRow .get_Value (i));
                   }
               }
               pRow.Store();
               pSortRow = plSortCursor.NextRow();
           }
           ITableCollection pTC = pMap as ITableCollection;
           pTC.AddTable(plStable);
         
        }
        
    }

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.