1.开始编辑,save feature property,停止编辑
IWorkspace workspace = ((IDataset)pFeatureClass).Workspace;
IWorkspaceEdit workspaceEdit = workspace as IWorkspaceEdit;
然后开启编辑状态:
bool startEdit = workspaceEdit.IsBeingEdited();
if (!startEdit)
{
workspaceEdit.StartEditing(false);
}
workspaceEdit.StartEditOperation();
然后获取IFeatureCursor和IFeature:
pFeatureCursor = pFeatureClass.Search(pQueryFilter, false);
//注意这里一定要为false,因为http://forums.arcgis.com/threads/45879-Cannot-call-Store-on-a-recycled-row-while-editing
//如果为true可能会产生0x80040958的错误
pFeature = pFeatureCursor.NextFeature();
然后用IFeature.set_Value()方法对Feature进行属性表值的修改:
pFeature.set_Value(i, valueToSet);
修改完成,要用IFeature.store()方法保存:
pFeature.Store();
然后最好将Feature释放掉,再进行接下来的修改:
System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeature);
pFeature = null;
pFeature = pFeatureCursor.NextFeature();
接下来用IFeatureCursor.Flush():
pFeatureCursor.Flush();
System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);
最后停止编辑状态:
workspaceEdit.StopEditOperation();
startEdit = workspaceEdit.IsBeingEdited();
if (!startEdit)
{
workspaceEdit.StopEditing(true);
}
2.获取图层
1 public IFeatureLayer GetFeatureLayerFromMap(string LayerName, IMap pMap) 2 { 3 IFeatureLayer rLayer = null; 4 for (int i = 0; i < pMap.LayerCount; i++) 5 { 6 ESRI.ArcGIS.Carto.ILayer lyr = pMap.get_Layer(i); 7 if (lyr is FeatureLayer) 8 { 9 if (lyr.Name.ToUpper() == LayerName.ToUpper()) 10 { 11 rLayer = lyr as IFeatureLayer; 12 break; 13 } 14 else 15 { 16 IFeatureClass tFeaCls = (lyr as IFeatureLayer).FeatureClass; 17 if (tFeaCls != null && (tFeaCls as IDataset).Name.ToUpper() == LayerName.ToUpper()) 18 { 19 rLayer = lyr as IFeatureLayer; 20 return rLayer; 21 } 22 else if (tFeaCls != null && (tFeaCls as IDataset).Name.Contains(".")) 23 { 24 if ((tFeaCls as IDataset).Name.Substring((tFeaCls as IDataset).Name.IndexOf(".") + 1).ToUpper() == LayerName.ToUpper()) 25 { 26 rLayer = lyr as IFeatureLayer; 27 return rLayer; 28 } 29 } 30 } 31 } 32 else if (lyr is IGroupLayer) 33 { 34 rLayer = GetFeatureLayerFromGroupLayer(lyr, LayerName); 35 if (rLayer != null) 36 break; 37 } 38 } 39 return rLayer; 40 }