Select to view content in your preferred language

Edit quickly great amout of data like the field calculator

1211
7
01-22-2013 05:02 AM
LionelMartz
Emerging Contributor
Is there any possibility to edit a great amout of rows ?
I think about this because the the field calculator of arcmap works quite fast.

The onlything i found was somthing like

public void UseUpdateCursor(IFeatureClass featureClass)
{
  // Restrict the number of features to be updated.
  IQueryFilter queryFilter = new QueryFilterClass();
  queryFilter.WhereClause = "NAME = 'Highway 104'";
  queryFilter.SubFields = "TYPE";

  // Use IFeatureClass.Update to populate IFeatureCursor.
  IFeatureCursor updateCursor = featureClass.Update(queryFilter, false);

  int typeFieldIndex = featureClass.FindField("TYPE");
  IFeature feature = null;
  try
  {
    while ((feature = updateCursor.NextFeature()) != null)
    {
      feature.set_Value(typeFieldIndex, "Toll Highway");
      updateCursor.UpdateFeature(feature);
    }
  }
  catch (COMException comExc)
  {
    // Handle any errors that might occur on NextFeature().
  }

  // If the cursor is no longer needed, release it.
  Marshal.ReleaseComObject(updateCursor);
}


But that takes 5 seconds for just 2000 rows... what is not as fast as I hoped..

Is there a way to do it faster? I ask because the field calculator does that much faster.
0 Kudos
7 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Lionel,

The new python arcpy.da.UpdateCursor is extremely fast.  With a quick test, I was able to update approx 12,000 rows in less than 2 seconds.
0 Kudos
LionelMartz
Emerging Contributor
Is this also available/fast in 10.0 ?
0 Kudos
JakeSkinner
Esri Esteemed Contributor
The arcpy.da.UpdateCursor is only available at 10.1.  You can still use the arcpy.UpdateCursor at 10.0.  The same test updated the rows in a little over 3 seconds.
0 Kudos
LionelMartz
Emerging Contributor
Where can i find how to get acces to arcpy in .NET-application. At the moment this is a standalone ArcEngine software working on ArcSDE Database.
0 Kudos
LeoDonahue
Deactivated User
Hi Lionel,

The problem is we don't know what ESR's code does when we do a field calculate to make it fast.  We don't know "how" QueryFilter and the Search methods work together, and as programmers we only concern ourselves with the contract, not the how.

Have you considered applying a QueryDef instead of a QueryFilter and then pass null to the search method where it expects a QueryFilter?  This way one might hope that you are really only iterating over the records you want updated.  Then reset the QueryDef to nothing when you are done.

Just a thought.
0 Kudos
LionelMartz
Emerging Contributor
I'm afraid I did no understand how to replace the QueryFilter by a QueryDef because of .Update and .Search methods only accept qFilter.
Unfortunately I still not found somthing faster.
I now also tried to use the ITableWrite and passed all affected rows in a ISet to the TableWrite method.. also same time.
0 Kudos
LeoDonahue
Deactivated User
Create a QueryDef and give it the same subfields and where clause as your QueryFilter.

  // Use IFeatureClass.Update to populate IFeatureCursor.   IFeatureCursor updateCursor = featureClass.Update(queryFilter, false);
// Use IFeatureClass.Update to populate IFeatureCursor.   IFeatureCursor updateCursor = featureClass.Update(null, false);

Change queryFilter to null.  You don't even need to create a queryfilter.  Having a null queryfilter would normally return all rows, but since you're defining a QueryDef, it will be limited to your where clause.
I have no idea if this is even faster than a normal query filter, it's ust a suggestion.

And remember, ArcMap is not using .NET to do field calculations.
0 Kudos