定義查詢(根據欄位值顯示要素)
public static void ShowFeaturesByFieldValue(this IFeatureLayer pFeatureLayer, string filedName, string value)
{
if (pFeatureLayer == null)
{
return;
}
ESRI.ArcGIS.Carto.IFeatureLayerDefinition pDef = (ESRI.ArcGIS.Carto.IFeatureLayerDefinition)pFeatureLayer;
IActiveView activeView = ArcMap.Document.FocusMap as IActiveView;
string mWhere = string.Empty;
if (value.Length == 0)
{
mWhere = "";
}
else
{
mWhere = filedName + "='" + value + "'";
}
//清除現有選擇
pDef.DefinitionExpression = "";
activeView.Refresh();
pDef.DefinitionExpression = mWhere;
activeView.Refresh();
}
public static void ShowFeaturesByFieldValue(IMap map, IFeatureLayer pFeatureLayer, string filedName, string value)
{
ESRI.ArcGIS.Carto.IFeatureLayerDefinition pDef = (ESRI.ArcGIS.Carto.IFeatureLayerDefinition)pFeatureLayer;
IActiveView activeView = map as IActiveView;
string mWhere = string.Empty;
if (value.Length == 0)
{
mWhere = "";
}
else
{
mWhere = filedName + "='" + value + "'";
}
//清除現有選擇
pDef.DefinitionExpression = "";
activeView.Refresh();
pDef.DefinitionExpression = mWhere;
activeView.Refresh();
}