Edit operation fails creating features

176
4
Jump to solution
a month ago
JeffreySauder
New Contributor II

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..

Tags (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
SeanJones
Esri Regular Contributor

Thanks, that message is a fallback if  the edit operation doesn't have enough information either from the geodatabase or its own routines. Like you, I would have expected a "field not found" message. I'll put in an issue to improve that.

View solution in original post

4 Replies
SeanJones
Esri Regular Contributor

Jeffrey,

Assuming the execute is returning False, check the EditOperation.ErrorMessage property to see if the error was reported.

Reply
0 Kudos
JeffreySauder
New Contributor II

I did finally get this to work, but the error in the ErrorMessage property was simply "Edit Operation Failed".  I spent a good part of the day troubleshooting this, I started with just the shape and that worked, then I would add a field one at a time and test it.  Turns out a field name was incorrect, Arcobjects would have indicated that ("Field name <fn> not found" or something like that), I never got any error more specific that it just failed

 

Reply
0 Kudos
SeanJones
Esri Regular Contributor

Thanks, that message is a fallback if  the edit operation doesn't have enough information either from the geodatabase or its own routines. Like you, I would have expected a "field not found" message. I'll put in an issue to improve that.

View solution in original post

JeffreySauder
New Contributor II

The more specific error message would be extremely helpful in the future, thank you for looking into improving that.

Reply
0 Kudos