Hi Karen,
We are still trying to figure out what exactly is causing this issue. It appears to be data related. In the meantime I received a workaround that will fix this issue for the time being. The workaround writes over the 'null' geometry in an EditOperation call back, it is using the Geodatabase API to do so. The Geodatabase API doesn't seem to have any problems with the data. I modified the code you sent me with the EditOperation call back workaround below.
protected override async void OnClick()
{
var sourceLayerName = "Source";
var modifyLayerName = "Modify";
var SourceFieldName = "OBJECTID";
var ModifyFieldName = "OBJECTID";
var selectionSourceQuery = $@"{SourceFieldName} = 1";
var selectionModifyQuery = $@"{ModifyFieldName} = 117";
var sourceLayer = MapView.Active.Map.GetLayersAsFlattenedList().Where((l) => l.Name == sourceLayerName).FirstOrDefault() as FeatureLayer;
if (sourceLayer == null)
{
MessageBox.Show($@"Unable to find {sourceLayerName} in the active map");
return;
}
var modifyLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(f => f.Name == modifyLayerName);
if (modifyLayer == null)
{
MessageBox.Show($@"Unable to find {modifyLayerName} in the active map");
return;
}
await QueuedTask.Run(() =>
{
// search the source for the matching parcel record
// copy only one polygon
Geometry sourcePolygon = null;
using (var cursor = sourceLayer.Search(new QueryFilter() { WhereClause = selectionSourceQuery }))
{
if (cursor.MoveNext())
{
using (var myFeature = cursor.Current as Feature)
{
sourcePolygon = myFeature.GetShape().Clone();
}
}
}
if (sourcePolygon == null)
{
MessageBox.Show($@"The add-in was not able to find a parcel where '{selectionSourceQuery}' is true.");
return;
}
using (Table table = modifyLayer.GetTable())
{
EditOperation editOperation = new EditOperation
{
Name = "Modify a geometry callback"
};
editOperation.Callback(context =>
{
QueryFilter filter = new QueryFilter { WhereClause = selectionModifyQuery };
using (RowCursor rowCursor = table.Search(filter, false))
{
while (rowCursor.MoveNext())
{
using (Feature feature = (Feature)rowCursor.Current)
{
// In order to update the Map and/or the attribute table.
// Has to be called before any changes are made to the row.
context.Invalidate(feature);
feature.SetShape(sourcePolygon);
//After all the changes are done, persist it.
feature.Store();
// Has to be called after the store too.
context.Invalidate(feature);
}
}
}
}, table);
// create the polygon feature
editOperation.Modify(modifyLayer, 117, sourcePolygon);
if (!editOperation.Execute())
{
MessageBox.Show($@"Unable to create a new '{sourceLayer}' record: {editOperation.ErrorMessage}");
}
}
});
}
I will give you an update on our findings.