矢量数据的查询与选择显示
/*按某属性值查询,并将查询结果显示在一个新的图层中*/
// 将图层声明为矢量图层
IFeatureLayer pFeatureLayer = GetGallery(gallery) as IFeatureLayer;
// 创建选择集
IFeatureSelection pFeatSel;
pFeatSel = pFeatureLayer as IFeatureSelection;
// 设定选定的颜色
Color color = this.SelectedLineColor;
pFeatSel.SelectionColor = GetRGB(color.R, color.G, color.B);
// 创建查询器及查询添加
IQueryFilter pQueryFilter;
pQueryFilter = new QueryFilterClass();
pQueryFilter.WhereClause = "FID = " + str;
// 开始选择 注意第二个参数 New 是新建
pFeatSel.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
// Add 是叠加
pFeatSel.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultAdd, false);
// 矢量图层定义
IFeatureLayerDefinition pFeatLyrDef;
pFeatLyrDef = pFeatureLayer as IFeatureLayerDefinition;
// 将当前选择的数据创建至新图层
string layerName = "MyLayer";
IFeatureLayer pnewFeat;
pnewFeat = pFeatLyrDef.CreateSelectionLayer(layerName, true, "", "");