I am playing with the ArcGIS Pro SDK, and got stuck when trying to delete a feature from a featureclass using an EditOperation.
While FeatureClass.DeleteRows() works fine, the following code throws an error: No parameterless constructor defined for this object.
var result = await QueuedTask.Run(() =>
{
using (var gdb = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\Data\Test.gdb"))))
{
var fc = gdb.OpenDataset<FeatureClass>("punten");
var cursor = fc.Search(null, false);
if (cursor.MoveNext())
{
var editOp = new EditOperation
{
Name = "Een test"
};
editOp.Delete(cursor.Current);
return editOp.Execute();
}
return false;
}
});
Also, modifying a feature works perfect:
editOp.Modify(cursor.Current, "test", "Hello");
Am I missing something?
This has been fixed in Pro 2.2, sorry for the inconvenience. Thanks
As a workaround, you should be able to use the EditOperation.Delete(MapMember, Int64) override, using the layer and ObjectID.
Yes, working on a MapMember works. In this case though, I was trying to edit a featureclass that was not added to a map.
As an aside, the FeatureClass, RowCursor, and Row classes all implement System.IDisposable. For correct object lifetime management, you should wrap usage of those variables in a using block. You may have simply removed that code to simplify the sample, but I wasn't sure. (This does not have any impact on the actual delete bug).
We're planning on clarifying this in the geodatabase conceptual documentation in the next release.
Yes, thanks for the reminder about disposing objects.
I was wondering, are Row and Feature objects meant to be short lived, or is it OK to keep them in memory? What are the best practices?
The best practice is definitely to call Dispose on Row and Feature objects. Keeping these objects around in memory can cause the system to hold onto file handles or database connections.