码迷,mamicode.com
首页 > Windows程序 > 详细

【转】C# ArcgisEngine开发中,对一个图层进行过滤,只显示符合条件的要素

时间:2015-06-16 18:20:51      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

有时候,我们要对图层上的地物进行有选择性的显示,以此来满足实际的功能要求。

按下面介绍的方法可轻松实现图层属性过滤显示:

  1、当图层已经加载时

 private void ShowByFilter(AxMapControl sMapCtr, IFeatureLayer sFlyr, string sFilter)

        {

            ESRI.ArcGIS.Carto.IFeatureLayerDefinition pDef = (ESRI.ArcGIS.Carto.IFeatureLayerDefinition)sFlyr;

 

            pDef.DefinitionExpression = sFilter;

 

            sMapCtr.ActiveView.Refresh();

        }

2、当图层尚未加载时

private IFeatureClass GetFeatureClass(IWorkspace pWS, string sTabName, string sAttrFilter)

        {

            try

            {

                if (pWS == null || sTabName == null) return null;

 

                IFeatureWorkspace pFWS = pWS as IFeatureWorkspace;

                IFeatureClass pFC = null;

 

                pFC = pFWS.OpenFeatureClass(sTabName);

 

                IQueryDef pQueryDef = pFWS.CreateQueryDef();

                pQueryDef.Tables = sTabName;

                pQueryDef.WhereClause = sAttrFilter;

 

                IQueryName2 pQueryName = new FeatureQueryNameClass();

                pQueryName.PrimaryKey = pFC.OIDFieldName;

                pQueryName.QueryDef = pQueryDef;

 

                IDataset pDS = (IDataset)pFWS;

 

                IWorkspaceName pWSName = (IWorkspaceName)pDS.FullName;

                IDatasetName pDSName = (IDatasetName)pQueryName;

 

                pDSName.WorkspaceName = pWSName;

                IName pName = (IName)pQueryName;

                pFC = pName.Open() as IFeatureClass;

 

                return pFC;

            }

            catch

            {

                return null;

            }

        }

 

【转】C# ArcgisEngine开发中,对一个图层进行过滤,只显示符合条件的要素

标签:

原文地址:http://www.cnblogs.com/joysky/p/4581208.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!