开始会话编辑时无法编辑要素图层

时间:2019-03-26 08:49:18

标签: gis arcgis arcobjects

我正在开发基于ArcGIS Engine的独立应用程序,当我开始使用以下代码块进行会话编辑时:

//Declare the Engine editor at the class level.
private IEngineEditor m_engineEditor = new EngineEditorClass();

private void StartEditing(IMapControl2 m_mapControl)
{
    IMap map = m_mapControl.Map;

    //If an edit session has already been started, exit.
    if (m_engineEditor.EditState != esriEngineEditState.esriEngineStateNotEditing)
        return ;

    //Start editing the workspace of the first feature layer found.
    for (int layerCounter = 0; layerCounter <= map.LayerCount - 1; layerCounter++)
    {
        ILayer currentLayer = map.get_Layer(layerCounter);
        if (currentLayer is IFeatureLayer)
        {
            IFeatureLayer featureLayer = currentLayer as IFeatureLayer;
            IDataset dataset = featureLayer.FeatureClass as IDataset;
            IWorkspace workspace = dataset.Workspace;
            m_engineEditor.StartEditing(workspace, map);
            ((IEngineEditLayers)m_engineEditor).SetTargetLayer(featureLayer);
            break;
        }
    }
}

发生了异常,错误代码:HRESULT:0x80004005(E_FAIL))。请帮助我

1 个答案:

答案 0 :(得分:0)

询问Google并阅读ArcGIS Engine文档后。我发现我的SDE GeoDatabase不允许编辑数据,因为我关闭了ArcGIS GeoDatabase的版本管理器。启用它并添加一些代码以检查要素图层是否可编辑。

IEngineEditLayers m_engineLayersEditor = m_engineEditor as IEngineEditLayers;
if (!m_engineLayersEditor.IsEditable(featureLayer))
{
    MessageBox.Show("Can not start editing. Because feature layer is not allow editing", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}