在ArcGlobe三维环境中进行数据查询(.net)

本文介绍了一个GIS应用中实现查询功能的具体方法。通过图层选择和输入查询条件,系统能够从不同的图层中筛选出符合要求的数据,并将结果展示在列表中。支持多种图层类型,如堤防和险工险段等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/// <summary>
        /// 查询功能
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnOK_Click(object sender, EventArgs e)
        {
            try
            {
                //图层名称
                String LayerName = this.CbxLayer.Text;
        //查询条件                
                String SearchText = this.TbxName.Text;
                if (SearchText == String.Empty)
                {
                   
                    MessageBox.Show("查询条件不允许为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    TbxName.Focus();
                    //清空数据列表
                    this.dg1.DataSource = null;
                    //跳出查询
                    return;
                }
        //当前视图
                IScene scene = this.axGlobeControl1.Globe.GlobeDisplay.Scene;
        //查询器
                IQueryFilter pQueryFilter = new QueryFilterClass();
                IActiveView pActiveView;
                pActiveView = (IActiveView)scene;
                //清空当前视图
                scene.ClearSelection();

                IFeatureLayer pFeatureLayer;
             
                pFeatureLayer = (IFeatureLayer)scene.get_Layer(GetLayerId(LayerName, scene));
                //判断要查询的图层
                if (LayerName == "堤防")
                {
                    //查询条件
                    pQueryFilter.WhereClause = "XMMC like '%" + SearchText + "%'";


                }
                else if (LayerName == "险工险段")
                {
                    //查询条件
                    pQueryFilter.WhereClause = "BZ like '%" + SearchText + "%'";


                }
                ......
              
                IFeatureCursor pFeatureCursor;
                //查询
                pFeatureCursor = pFeatureLayer.FeatureClass.Search(pQueryFilter, false);
                IFeature pFeature;
                pFeature = pFeatureCursor.NextFeature();
                IFields pFields = pFeatureCursor.Fields;

                int fieldIndex = 0;
                int fieldIndexName = 0;
                if (LayerName == "堤防")
                {
                    fieldIndex = pFields.FindField("NAME");
                    fieldIndexName = pFields.FindField("XMMC");

                }
                else if (LayerName == "险工险段")
                {
                    fieldIndex = pFields.FindField("NAME");
                    fieldIndexName = pFields.FindField("BZ");

                }
                ......
                pfeat = pFeature;

                if (pFeature == null)
                {
                    MessageBox.Show("您所查询的结果不存在!");
                    TbxName.Select();
                    TbxName.Focus();
                    this.dg1.DataSource = null;
                    return;
                }
                //绑定DataTable 
                DataTable dt = new DataTable();
                DataColumn dc1 = new DataColumn();
                dc1.ColumnName = "工程代码";
                DataColumn dc2 = new DataColumn();
                dc2.ColumnName = "工程名称";

                dt.Columns.Add(dc1);
                dt.Columns.Add(dc2);

                string Code = String.Empty;
                string Name = String.Empty;
                while (pFeature != null)
                {
                    //scene.SelectFeature(pFeatureLayer, pFeature);

                    Code = pFeature.get_Value(fieldIndex) as string;
                    Name = pFeature.get_Value(fieldIndexName) as string;
                    DataRow dr = dt.NewRow();
                    dr[0] = Code;
                    dr[1] = Name;

                    dt.Rows.Add(dr);
                    pFeature = pFeatureCursor.NextFeature();
                }
                //绑定列表
                this.dg1.DataSource = dt.DefaultView;
            }
            catch
            {
                MessageBox.Show("异常!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.dg1.DataSource = null;
            
            
            }
        }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值