获取要素集中字段的唯一值
/// <summary>
/// 获取要素集中字段的唯一值
/// </summary>
/// <param name="featureClass">图层</param>
/// <param name="fieldName">字段名称</param>
/// <returns></returns>
public static List<double> GetUniquFieldValue(IFeatureClass featureClass, string fieldName)
{
List<double> pList = new List<double>();
IFeatureCursor pFeatureCursor = featureClass.Search(null, false);
IDataStatistics pData = new DataStatisticsClass();
pData.Field = fieldName;
pData.Cursor = pFeatureCursor as ICursor;
IEnumerator pEnumerator = pData.UniqueValues;
pEnumerator.Reset();
while (pEnumerator.MoveNext())
{
string pFieldValue = pEnumerator.Current.ToString();
double a;
Double.TryParse(pFieldValue, out a);
pList.Add(a);
}
ReleaseFeatureCursor(pFeatureCursor);
return pList;
}
/// <summary>
/// 释放FeatureCursor
/// </summary>
/// <param name="featureCursor">需要释放的游标</param>
public static void ReleaseFeatureCursor(IFeatureCursor featureCursor)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);
}