标签:dna one arcengine space refresh pen private engine 加载
转自chanyinhelv原文 在ArcEngine下实现图层属性过滤的两种方法
有时候,我们要对图层上的地物进行有选择性的显示,以此来满足实际的功能要求。
按下面介绍的方法可轻松实现图层属性过滤显示:
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; } }
2、当图层尚未加载时
由属性过滤后的FeatureClass创建图层、加载到地图的过程就比较简单了
有时候,我们要对图层上的地物进行有选择性的显示,以此来满足实际的功能要求。
按下面介绍的方法可轻松实现图层属性过滤显示:
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;
}
}
由属性过滤后的FeatureClass创建图层、加载到地图的过程就比较简单了
标签:dna one arcengine space refresh pen private engine 加载
原文地址:http://www.cnblogs.com/arxive/p/6262801.html