• ArcEngine 数据编辑(IWorkspaceFactory)


    数据编辑做过很多次,没怎么出现问题,今天出现了问题,浪费了大半天,记录一下。

    问题:修改Featrue的属性,修改后停止编辑,但是没有提示是否保存修改

    原因:在编辑数据的时候没有加StartEditOperation方法。

    解决办法:在修改数据的时候加上StartEditOperationStopEditOperation方法

    代码如下:

    1、打开工作空间和开始编辑  

     ''' <summary>
        ''' 开始编辑VB
        ''' </summary>
        ''' <remarks></remarks>
        Public Function StartEdit() As Boolean
        If IsNothing(pWorkspaceEdit) Then
          Dim pWorkspaceFactory As IWorkspaceFactory = New ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactory
          Dim dataset As IDataset = pPointFeatureLayer.FeatureClass
          Dim workspace As IWorkspace = pWorkspaceFactory.OpenFromFile(dataset.Workspace.PathName, 0)
          pWorkspaceEdit = workspace
        End If
        pWorkspaceEdit.StartEditing(True)
      End Function
            //开始编辑C#
           if(pWorkspaceEdit==null)
           {
              IWorkspaceFactory pWorkspaceFactory =new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactory();
              IDataset dataset =pFeatureLayer.FeatureClass as IDataset;
              IWorkspace workspace = pWorkspaceFactory.OpenFromFile(dataset.Workspace.PathName, 0);
              pWorkspaceEdit = workspace as IWorkspaceEdit;
              pWorkspaceEdit.StartEditing(true);
           }

    2、开始操作和停止操作

      Public Function StartOperation() As Boolean
        pWorkspaceEdit.StartEditOperation()
        Return True
      End Function
      Public Function StopOperation() As Boolean
        pWorkspaceEdit.StopEditOperation()
        Return True
      End Function

    3、保存编辑

        ''' <summary>
        ''' 保存编辑
        ''' </summary>
        ''' <remarks></remarks>
        Public Function StopEdit() As Boolean
        'pWorkspaceEdit.IsBeingEdited()
            Dim bSave As Boolean
    
            If Not HasEdits() Then
                bSave = False
            Else
                Dim r As System.Windows.Forms.DialogResult
                r = MessageDialog.Show("是否保存编辑?", "提示", Windows.Forms.MessageBoxButtons.YesNoCancel)
                Select Case r
                    Case Windows.Forms.DialogResult.Yes
                        bSave = True
                    Case Windows.Forms.DialogResult.No
                        bSave = False
                    Case Windows.Forms.DialogResult.Cancel
                        Return True
                End Select
            End If
        pWorkspaceEdit.StopEditing(bSave)
            Return True
        End Function
     
       Private Function HasEdits() As Boolean
            Dim bHasEdits As Boolean
            pWorkspaceEdit.HasEdits(bHasEdits)
            Return bHasEdits
        End Function

    4、修改数据的地方

      m_editor.StartOperation()
        Dim pFieldIndex As Integer = pTagFeature.Fields.FindField(e.ChangedItem.PropertyDescriptor.Name)
        pTagFeature.Value(pFieldIndex) = e.ChangedItem.Value
        pTagFeature.Store()
        m_editor.StopOperation()
  • 相关阅读:
    1036 Boys vs Girls (25 分)
    1028 人口普查 (20 分)
    1004 成绩排名 (20 分)
    4.ServletContext接口
    5 .索引
    7.jQuery 的 基本绑定事件操作
    6.jQuery 操作元素的样式css
    1.servlet简介 + 我的第一个servlet程序
    5.jQuery 的 Class操作
    4.jQuery 操作文本内容
  • 原文地址:https://www.cnblogs.com/GIScore/p/5319854.html
Copyright © 2020-2023  润新知