I have a pro sdk add-in that I am using to calculate lines and write them to a feature class. I've tried shapefile, filegoedatabase, and enterprise geodatabase, all fail when I try to write the features. I have another add-in that does a similar thing and that one works OK. I have made sure that all fields in the feature class are in the dictionary, checked that nothing is null, the datatypes are correct, etc., still the edit operation fails with no explanation as to why. I put the code that I'm using below, the Layername "NewWater" is a file geodatabase feature class in the project.
async Task WriteToProjectLayer()
{
var addrLineLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where(l => l.Name == "NewWater").FirstOrDefault();
await QueuedTask.Run(() =>
{
EditOperation aLineEOP = new EditOperation();
aLineEOP.Name = "WaterLineEdit";
foreach (var a in GilbertWaterLines)
{
var attr = new Dictionary<string, object>
{
{"Shape",a.WaterLineShape },
{"PPG_NUMBER",a.PPG_NUMBER },
{"PPG_FTYPE_CD",a.PPG_FTYP_CD },
{"PPG_TTYPE_CD",a.PPG_TTYP_CD },
{"PPG_FRM_END",a.PPG_FRM_END },
{"PPG_TO_END",a.PPG_TO_END }
};
aLineEOP.Create(addrLineLayer, attr);
}
var result = aLineEOP.Execute();
MessageBox.Show("Edit worked = " + result.ToString());
Project.Current.SaveEditsAsync();
});
}
I have also tried this with a shapefile, connecting to the shapefile instead of using the project layer. I get the same result:
async Task WriteToGeoDB()
{
await QueuedTask.Run(() =>
{
var uri = new System.Uri("c:\\TestWater");
FileSystemConnectionPath shpPath = new FileSystemConnectionPath(uri, FileSystemDatastoreType.Shapefile);
var sFile = new FileSystemDatastore(shpPath);
var sTable = sFile.OpenDataset<Table>("WaterLines");
EditOperation eOP = new EditOperation();
foreach (GilbertWaterLine a in GilbertWaterLines)
{
var attr = new Dictionary<string, object> {
{"Shape",a.WaterLineShape },
{"PPG_NUMBER",a.PPG_NUMBER },
{"PPG_FTYPE_C",a.PPG_FTYP_CD },
{"PPG_TTYPE_C",a.PPG_TTYP_CD },
{"PPG_FRM_EN",a.PPG_FRM_END },
{"PPG_TO_END",a.PPG_TO_END },
};
eOP.Create(sTable, attr);
}
var result = eOP.Execute();
MessageBox.Show("Edit worked = " + result.ToString());
Project.Current.SaveEditsAsync();
});
MessageBox.Show("All Finished");
}
I'm not sure what could be the problem, I am using pretty much this exact same code elsewhere successfully. I have tested this with a small sample of features, making sure there were no nulls or 0 length line segments. If there was at least an explanation of what the edit operation was having a problem with, I could address that..