Start editing programmatically - how to get the workspace to edit?

3053
4
Jump to solution
05-15-2014 06:02 AM
FossiG_
New Contributor III
Hello experts,

when trying to start an edit session programmatically I am a little stuck with the workspace to edit.
Everything works fine, as long as I use feature classes belonging to a feature dataset. But as soon as I use a standalone feature class the featureDataset attribute (see code below) becomes null (of course).

Is it just bad practice to have standalone feature classes? Or is there another way, to obtain the right edit workspace?

Thanks in advance, any hint is appreciated.

Regards
Fossi

//http://resources.esri.com/help/9.3/ArcGISDesktop/dotnet/2626201e-de60-4bab-bb1c-d16fcd4f8c4b.htm#NETFeature         private void startEditing(ESRI.ArcGIS.Framework.IApplication ArcMap)         {             ESRI.ArcGIS.Geodatabase.IFeatureClass m_featureClass;             ESRI.ArcGIS.Editor.IEditor m_editor;              ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument = (ESRI.ArcGIS.ArcMapUI.IMxDocument)ArcMap.Document;             ESRI.ArcGIS.ArcMapUI.IContentsView curTOC = mxDocument.CurrentContentsView;             //Create a method to get a reference to the feature class or add the ArcGIS Desktop snippet.             //http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Get_FeatureClass_of_Selected_Feature_Layer_in_Contents_View_Snippet/00490000004r000000/             m_featureClass = ArcMapHelperFunctions.GetFeatureClassOfSelectedFeatureLayerInContentsView(curTOC);              //Once the feature class has been referenced, get the workspace to edit by creating an IFeatureWorkspace             //and setting an IWorkspace object to the feature workspace using a cast.              ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featWork = m_featureClass.FeatureDataset.Workspace as ESRI.ArcGIS.Geodatabase.IFeatureWorkspace;              ESRI.ArcGIS.Geodatabase.IWorkspace editWorkspace = featWork as ESRI.ArcGIS.Geodatabase.IWorkspace;              //Start an edit session on the workspace holding the feature class, which must be in a feature dataset.             ESRI.ArcGIS.esriSystem.UID editorUid = new ESRI.ArcGIS.esriSystem.UID();             editorUid.Value = "esriEditor.Editor";             m_editor = ArcMapHelperFunctions.app.FindExtensionByCLSID(editorUid) as ESRI.ArcGIS.Editor.IEditor3;              m_editor.StartEditing(editWorkspace);         }
0 Kudos
1 Solution

Accepted Solutions
NeilClemmons
Regular Contributor III
Sorry, yes.  I meant IDataset instead of IGeoDataset.

View solution in original post

0 Kudos
4 Replies
NeilClemmons
Regular Contributor III
QI from IFeatureClass to IGeoDataset and get the workspace from there instead of going through the feature dataset.

Dim workspace As IWorkspace = DirectCast(featureClass, IGeoDataset).Workspace

In C# that would be something like this:
IWorkspace workspace = (featureClass As IGeoDataset).Workspace
0 Kudos
FossiG_
New Contributor III
Hello Neil,

thanks for your help and putting me on the right track! ( I will never get used to this "casting interfaces" style. Kept looking for a member "workspace" at these classes :o).

Umm, could it be, that you meant IDataset instead of IGeoDataset? In my (poor) understanding IGeoDataset implements only Extent and SpatialReference, whereas IDataset has Workspace amongst others. Please let me know if I overlooked another way, solving this with IGeoDataset. I am glad for any hint.

Here is the new approach, which seems to work fine
//http://resources.esri.com/help/9.3/ArcGISDesktop/dotnet/2626201e-de60-4bab-bb1c-d16fcd4f8c4b.htm#NETFeature
        private void startEditing(ESRI.ArcGIS.Framework.IApplication ArcMap)
        {
            ESRI.ArcGIS.Geodatabase.IFeatureClass m_featureClass;
            ESRI.ArcGIS.Editor.IEditor m_editor;

            ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument = (ESRI.ArcGIS.ArcMapUI.IMxDocument)ArcMap.Document;
            ESRI.ArcGIS.ArcMapUI.IContentsView curTOC = mxDocument.CurrentContentsView;
            //Create a method to get a reference to the feature class or add the ArcGIS Desktop snippet.
            //http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Get_FeatureClass_of_Selected_Feature_Layer_in_Contents_View_Snippet/00490000004r000000/
            m_featureClass = ArcMapHelperFunctions.GetFeatureClassOfSelectedFeatureLayerInContentsView(curTOC);

            //Once the feature class has been referenced, get the workspace to edit by creating an IFeatureWorkspace
            //and setting an IWorkspace object to the feature workspace using a cast. 
            ESRI.ArcGIS.Geodatabase.IWorkspace editWorkspace = (m_featureClass as ESRI.ArcGIS.Geodatabase.IDataset).Workspace;
            
            //Start an edit session on the workspace holding the feature class, which must be in a feature dataset.
            ESRI.ArcGIS.esriSystem.UID editorUid = new ESRI.ArcGIS.esriSystem.UID();
            editorUid.Value = "esriEditor.Editor";
            m_editor = ArcMapHelperFunctions.app.FindExtensionByCLSID(editorUid) as ESRI.ArcGIS.Editor.IEditor3;

            m_editor.StartEditing(editWorkspace);
        }


Regards
Fossi
0 Kudos
NeilClemmons
Regular Contributor III
Sorry, yes.  I meant IDataset instead of IGeoDataset.
0 Kudos
FossiG_
New Contributor III
Sorry, yes.  I meant IDataset instead of IGeoDataset.


Thanks for the clarification and your great help!
0 Kudos