Updating all attribute data in Feature Layer using ArcObjects

1423
3
02-17-2018 04:31 AM
ChristianDebono
New Contributor II

I have a layer with over 250,000+ features, and I want to update all the attribute data using ArcObjects and C#. I have written the code below and it takes around 3 hours to perform the update. Can you suggest whether the code below is efficient enough and any suggestion regarding the delta tables please?

 public void updateWithCursor(IWorkspace workspace, IFeatureClass featureClass, List<Update> updateList)
        {
            using (ComReleaser comReleaser = new ComReleaser())
            {
                IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace;

                // Start an edit session
                workspaceEdit.StartEditing(false);

                // Start an edit operation
                workspaceEdit.StartEditOperation();
                // Use IFeatureClass.Search to create a search cursor.
                IFeatureCursor searchCursor = featureClass.Search(null, false);
                comReleaser.ManageLifetime(searchCursor);

                // Find the positions of the fields used to get and set values.
                int idIndex = featureClass.FindField("ID");
                int serialIndex = featureClass.FindField("SERIAL");
                int cityIndex = featureClass.FindField("CITY");
                int updateDateIndex = featureClass.FindField("UPDATEDATE");
                
                int counter = 0;
                IFeature feature = null;
                while ((feature = searchCursor.NextFeature()) != null)
                {
                    string searchValue = feature.get_Value(idIndex).ToString();

                    if (searchValue != "")
                    {
                        Update upd = updateList.SingleOrDefault(x => x.id == searchValue);

                        if (upd != null)
                        {                            
                            feature.set_Value(serialIndex , upd.serialNo);
                            feature.set_Value(cityIndex , upd.city);
                            feature.set_Value(updateDateIndex, DateTime.Now);
                            feature.Store();
                        }
                        Console.WriteLine(counter++);
                    }
                }

                workspaceEdit.StopEditOperation();

                // Stop the edit session. The saveEdits parameter indicates the edit session
                // will be committed.
                workspaceEdit.StopEditing(true);
            }
        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Tags (1)
0 Kudos
3 Replies
ModyBuchbinder
Esri Regular Contributor

Hi

Use UpadteCursor and do not use StartEditing (you are not doing undo or redo).

Check this: http://desktop.arcgis.com/en/arcobjects/latest/net/webframe.htm#521a263d-dcee-47b9-b41b-33ef3fb4c558... 

Have Fun

Mody

0 Kudos
ChristianDebono
New Contributor II

My data is versioned, If I don't use StartEditing; an exception is thrown 'Objects in this class cannot be updated outside an edit session'

0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi,

Have you tried ITransactions interface? It works without StartEditing fine on big quantities data with file or personal geodatabases. I have not tried it on SDE

0 Kudos