【转】C# ArcgisEngine开发中,对一个图层进行过滤,只显示符合条件的要素
有时候,我们要对图层上的地物进行有选择性的显示,以此来满足实际的功能要求。
按下面介绍的方法可轻松实现图层属性过滤显示:
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; } }
作者:GitLoft
出处:http://www.cnblogs.com/joysky/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。