通过sql语句discint可以查询不重复的记录,但这个对shapefile是不适用的,dbf数据不支持这个语法,看了下arcengine中的DataStatistics可以实现这样的需求。这个取得的数据是对shapefile也适用的。
相关代码如下:
///
/// 使用DataStatistics获取独一无二的记录,对shapefile文件也适用
///
/// 查询的游标
/// 字段
///
public static System.Collections.IEnumerator GetUniqueValue(ICursor pCursor, string field)
{
DataStatistics pData = new DataStatistics();
pData.Field = field;
pData.Cursor = pCursor;
System.Collections.IEnumerator enumerator = pData.UniqueValues;
enumerator.Reset();
while (enumerator.MoveNext())
{
object myObject = enumerator.Current;
Console.WriteLine("Value - {0}", myObject.ToString());
}
return pData.UniqueValues;
}
|
相关调用如下:
private void button1_Click(object sender, EventArgs e)
{
IFeatureClass pFeatClass; //通用的
IWorkspaceFactory pWorkspaceFactory;
IFeatureWorkspace pFeatWS;
//打开工作空间并添加shp文件
string filename = "d://temp//008-019l_Line.shp";
pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
pFeatWS = pWorkspaceFactory.OpenFromFile(@"D:\temp\", 0) as IFeatureWorkspace;
pFeatClass = pFeatWS.OpenFeatureClass("008-019l_Line");
ICursor pCursor =pFeatClass.Search(null, false) as ICursor;
System.Collections.IEnumerator debug = CommonFuction.GetUniqueValue(pCursor, "编码");
//object test = debug.Next();
}
阅读(1832) | 评论(0) | 转发(0) |