/// <summary> /// 复制旧要素图层(只包含选中字段) /// </summary> /// <param name="featureWorkspace">要素工作空间</param> /// <param name="selectionLayer">被复制要素图层</param> /// <param name="newLayerName">新图层名称</param> /// <returns></returns> private IFeatureLayer CopyOldFeatureLayerWithSelectFiled(IFeatureWorkspace featureWorkspace, IFeatureLayer selectionLayer, string newLayerName) { Dictionary <string, int> fidValue = DataTableInfoClass.GetColumnValueDictionary(newAttributeTable, "FID"); //FID值列表 List <string> columnName = DataTableInfoClass.GetAllColumnName(newAttributeTable); //表格所有列名 IWorkspaceEdit workspaceEdit = featureWorkspace as IWorkspaceEdit; if (workspaceEdit == null) { return(null); } //开始编辑 StartEdit(workspaceEdit); try { //以旧图层为基础创建新图层要素集合 IFeatureClass newFeatureClass = CreateNewFeatureClass(featureWorkspace, selectionLayer, newLayerName); //复制旧要素值到新要素集合 CopyFeatureValueToNewFeature(selectionLayer, newFeatureClass, fidValue, columnName); //停止并保存编辑 EndAndSaveEdit(workspaceEdit); //删除非选中字段 DeleteFeatureClassFields(newFeatureClass, columnName); return(FeatureInfoClass.GetFeatureLayer(newFeatureClass)); } finally { //撤销编辑 UndoEdit(workspaceEdit); } }
/// <summary> /// 删除要素 /// </summary> /// <param name="newAttributeTable">新属性表</param> private void DeleteFeatures(DataTable newAttributeTable) { //FID值 Dictionary <string, int> fidValue = DataTableInfoClass.GetColumnValueDictionary(newAttributeTable, "FID"); IFeatureCursor featureCursor = newLayer.FeatureClass.Search(null, false); IFeature feature = featureCursor.NextFeature(); while (feature != null) { //FID不在新属性表中,则删除 if (!fidValue.ContainsKey(feature.Value[0].ToString())) { feature.Delete(); } feature = featureCursor.NextFeature(); //游标移动 } }