|
阅读:1728回复:1
关于WorkspaceEdit 的 UndoEditOperation问题???
<STRONG>关于WorkspaceEdit 的 UndoEditOperation问题???<BR></STRONG>
<P> 最近想做个关于地图编辑方面的程序,就是在地图上创建图形,修改图形形状,大小之类的,用的是AE+C#.但是当我从地理数据库中读取featureclass到map layer中时,进行图元编辑,编辑完成后,保存编辑.程序运行到pWorkspaceEdit.StopEditOperation();</P> <P>还没执行pWorkspaceEdit.StopEditing(true); </P> <P>编辑的结果就已经存入了地理数据库中的featureclass中,不知道为什么会这样?</P> <P>但是同样的代码,我从shp文件中读取数据到layer中,程序运行到pWorkspaceEdit.StopEditing(true); 才会将结果保存.不知道为什么从地理数据库中读的featureclass到layer中运行到pWorkspaceEdit.StopEditOperation(); 就早早的保存完了结果.</P> <P>粗略代码如下</P> <P>IPropertySet pOutSDEPropset = new PropertySetClass();<BR> pOutSDEPropset.SetProperty("USER", "sde");<BR> pOutSDEPropset.SetProperty("PASSWORD", "wyf");<BR> pOutSDEPropset.SetProperty("VERSION", "SDE.DEFAULT");<BR> pOutSDEPropset.SetProperty("SERVER", "agrs-luxiangdong");<BR> pOutSDEPropset.SetProperty("INSTANCE", "esri_sde");<BR> IWorkspaceFactory WorkspaceFactory = new SdeWorkspaceFactoryClass();<BR> FeatureWorkspace = (IFeatureWorkspace)WorkspaceFactory.Open(pOutSDEPropset, 0);<BR> IFeatureLayer pflayer = new FeatureLayerClass();<BR> IFeatureClass lfeatureclass = FeatureWorkspace.OpenFeatureClass("buildingmap");<BR> pflayer.FeatureClass = lfeatureclass;<BR> pflayer.Name = lfeatureclass.AliasName;</P> <P> axMapControl1.Map.AddLayer((ILayer)pflayer);</P> <P>IDataset pDataset = (IDataset) pflayer.FeatureClass; </P> <P>IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pDataset.Workspace;</P> <P>pWorkspaceEdit.StartEditing(true); <BR>pWorkspaceEdit.EnableUndoRedo(); </P> <P>pWorkspaceEdit.StartEditOperation(); </P> <P>编辑过程..........</P> <P>pWorkspaceEdit.StopEditOperation(); //程序到这一步就已经把结果存入进去了</P> <P>pWorkspaceEdit.UndoEditOperation(); //此时已经不能撤销更改了</P> <P>pWorkspaceEdit.StopEditing(true); //最后这一句对结果保存没什么影响了,反正地理数据库中的结果已经改变了 </P> |
|
|
1楼#
发布于:2008-04-09 23:47
<P>你写得并没有什么错误</P>
<P> //IWorkspaceEdit Example</P> <P><BR> </P> <P> //e.g., nameOfFeatureClass = "States"<BR> //on ArcSDE use ISqlSyntax::QualifyTableName for fully qualified table names.<BR> public void IWorkspaceEdit_Example(IWorkspace workspace, string nameOfFeatureClass)<BR> {<BR> IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;<BR> IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(nameOfFeatureClass);<BR> IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace;<BR> //start editing with undo redo functionality<BR> workspaceEdit.StartEditing(true);<BR> workspaceEdit.StartEditOperation();<BR> IFeature feature = featureClass.GetFeature(1);<BR> feature.Delete();<BR> workspaceEdit.StopEditOperation();<BR> Console.WriteLine("Would you like to undo your operation? Y or N");<BR> string response = Console.ReadLine();<BR> if(response.ToUpper() == "Y")<BR> {<BR> workspaceEdit.UndoEditOperation();<BR> }<BR> bool hasEdits = false;<BR> workspaceEdit.HasEdits(ref hasEdits);<BR> if (hasEdits)<BR> {<BR> Console.WriteLine("Would you like to save your edits? Y or N");<BR> response = Console.ReadLine();<BR> if (response.ToUpper() == "Y")<BR> {<BR> workspaceEdit.StopEditing(true);<BR> }<BR> else<BR> {<BR> workspaceEdit.StopEditing(false);<BR> }<BR> }<BR> }</P> |
|
|