I am reading data from a database that is incompatible with ArcGIS Pro into an ESRI geodatabase using the .Net SDK. The database stores primary keys as GUIDs e.g. {e372ad91-9e24-4054-9454-5bb31657f2db} which is the same format as a GUID field in an ESRI file geodatabase (.gdb).
However, if I try to write these GUIDs to a file geodatabase, I get an exception at the line where I add the GUID field to the row buffer:
Name | Value | Type | |
---|---|---|---|
◢ | $exception | {"A general error when something is wrong with a Field."} | ArcGIS.Core.Data.GeodatabaseFieldException |
Are GUIDs in file geodatabases handled in a special way? I can't seem to write in new ones generated outside of ArcGIS Pro.
Thank you very much in advance.
Here is the basic outline of my code and a mock feature table to illustrate my question:
FacilityID | Name | OwnType | GUIDField |
---|---|---|---|
1 | Griffith Park | Municipal | {e372ad91-9e24-4054-9454-5bb31657f2db} |
2 | London | Municipal | {zyxqad91-7g76-9999-9434-5aa31657f2db} |
3 | India | Municipal | {abc1ad91-9e24-8888-1234-5aa12345f2db} |
public async Task CreatingAFeature() { string message = String.Empty; bool creationResult = false; await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => { using (Geodatabase geodatabase = new Geodatabase(new Geodatabase(new FileGeodatabaseConnectionPath(new Uri("filePath")));)))) using (FeatureClass featureClass = geodatabase.OpenDataset<FeatureClass>("FeatureClassName")) { //declare the callback EditOperation editOperation = new EditOperation(); editOperation.Callback(context => { FeatureClassDefinition facilitySiteDefinition = featureClass.GetDefinition(); int facilityIdIndex = facilitySiteDefinition.FindField("FACILITYID"); using (RowBuffer rowBuffer = featureClass.CreateRowBuffer()) { // Fill fields of row buffer rowBuffer["facilityId"] = 4; rowBuffer["NAME"] = "Griffith Park"; rowBuffer["OWNTYPE"] = "Municipal"; /* The line that throws the exception. Commenting out this line makes everything run fine I generate a new GUID here for the sake of the example. Trying to write a GUID from the dataset, or writing the GUID as a string also throws an exception. */ rowBuffer["GUIDField"] = Guid.NewGuid(); // The line that throws the exception. ... code continues
Solved! Go to Solution.
It looks like calling Guid.NewGuid() generates a global ID without braces around it.
Try this instead:
rowBuffer["GUIDField"] = "{" + Guid.NewGuid().ToString() + "}";
--Rich
It looks like calling Guid.NewGuid() generates a global ID without braces around it.
Try this instead:
rowBuffer["GUIDField"] = "{" + Guid.NewGuid().ToString() + "}";
--Rich
Hi Rich,
That works perfectly, thank you very much.