按字段值选择要素(高亮显示选择结果)
作者:互联网
/// <summary>
/// 按字段值选择要素(高亮显示选择结果)
/// </summary>
/// <param name="pFeatureLayer">要素图层</param>
/// <param name="fieldName">字段名称</param>
/// <param name="fieldValue">字段值</param>
public static void SelectFeatureByFilter(this IFeatureLayer pFeatureLayer, string fieldName, string fieldValue)
{
//string strWhereClause = string.Empty;
//strWhereClause = whereFieldName + " = '" + whereValue + "'";
//IQueryFilter pQueryFilter = new QueryFilterClass();
//pQueryFilter.WhereClause = strWhereClause;
IMap map = ArcMap.Document.FocusMap;
IActiveView pActiveView = map as IActiveView;
if (fieldName.Length > 0)
{
IFeatureSelection pFeatureSelection = pFeatureLayer as IFeatureSelection;
IQueryFilter pQueryFilter = new QueryFilterClass();
string strWhereClause = fieldName + " = '" + fieldValue + "'";
pQueryFilter.WhereClause = strWhereClause;//过滤条件,查询表达式
map.ClearSelection();
pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
}
else
{
map.ClearSelection();
}
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, pActiveView.Extent);
}
标签:段值,高亮,string,map,pActiveView,按字,fieldName,strWhereClause,pQueryFilter 来源: https://www.cnblogs.com/wzyong/p/16066446.html