Recently I was inserting features in a feature class but my code was rather slow so I looked around for another method and the following is what I found.
First you need to start an edit session and then you can use the code below. This is just a short body of code to give you an idea on how to use the different objects.
IFeatureCursor insertFeatCursor = outputFeatClass.Insert(true);
foreach (object featureToInsert in featuresToInsert)
{
IFeatureBuffer outputFeatBuffer = outputFeatClass.CreateFeatureBuffer();
// set the shape
outputFeatBuffer.Shape = ...
// set the different values
outputFeatBuffer.set_Value(fieldIndex, value);
// insert the feature buffer
insertFeatCursor.InsertFeature(outputFeatBuffer);
}
insertFeatCursor.Flush();
If you now save and close your edit session the features are inserted. The code for inserting rows in a table is very similar.
ITable table;
ICursor insertCursor = table.Insert(true);
IRowBuffer rowBuffer = table.CreateRowBuffer();
rowBuffer.set_Value(fieldIndex, value);
insertCursor.InsertRow(rowBuffer);
insertCursor.Flush();
If you have any comments or questions, let me know !!!
Related posts
Using foreach with the ICursor
Drag Drop from ArcCatalog
Pythonnet (call .NET from Python)
No comments:
Post a Comment