Return Value
An RowBuffer used to set the field values when calling CreateRow.
| Exception | Description |
|---|---|
| ArcGIS.Core.Data.Exceptions.GeodatabaseException | A geodatabase-related exception has occurred. |
No row is created in the database.
The returned RowBuffer does not have an object ID value.
{
Task GetVersionConflictsInfoInUpdateDeleteTypeAsync(
ServiceConnectionProperties featureServiceConnectionProperties,
string featureClassName) => QueuedTask.Run(() =>
{
// To illustrate the conflict between versions,
// the feature is updated in the child version and deleted in the parent version.
long featureObjectIDForEdit = Int64.MinValue;
// Get branch versioned service
using (Geodatabase fsGeodatabase = new Geodatabase(featureServiceConnectionProperties))
using (VersionManager versionManager = fsGeodatabase.GetVersionManager())
using (Version defaultVersion = versionManager.GetDefaultVersion())
using (Geodatabase defaultGeodatabase = defaultVersion.Connect())
using (FeatureClass defaultFeatureClass = defaultGeodatabase.OpenDataset<FeatureClass>(featureClassName))
using (FeatureClassDefinition defaultFeatureClassDefinition = defaultFeatureClass.GetDefinition())
{
// Create a feature in the default version to edit in a branch
defaultGeodatabase.ApplyEdits(() =>
{
using (RowBuffer rowBuffer = defaultFeatureClass.CreateRowBuffer())
{
rowBuffer["NAME"] = "Loblolly Pine";
rowBuffer["TREEAGE"] = 1;
rowBuffer[defaultFeatureClassDefinition.GetShapeField()] = new MapPointBuilderEx(new Coordinate2D(1, 1),
SpatialReferenceBuilder.CreateSpatialReference(4152, 0)).ToGeometry();
using (Feature feature = defaultFeatureClass.CreateRow(rowBuffer))
{
featureObjectIDForEdit = feature.GetObjectID();
}
}
});
// Add newly created feature in the filter
QueryFilter queryFilter = new QueryFilter { ObjectIDs = new List<long> { featureObjectIDForEdit } };
// Create a branch version
VersionDescription versionDescription = new VersionDescription("UpdateDeleteConflictType",
"Update-Delete version conflict type", VersionAccessType.Public);
// Edit the feature in the branch
using (Version editVersion = versionManager.CreateVersion(versionDescription))
using (Geodatabase branchGeodatabase = editVersion.Connect())
using (FeatureClass featureClass = branchGeodatabase.OpenDataset<FeatureClass>(featureClassName))
using (RowCursor rowCursor = featureClass.Search(queryFilter, false))
{
branchGeodatabase.ApplyEdits(() =>
{
while (rowCursor.MoveNext())
{
using (Row row = rowCursor.Current)
{
row["TREEAGE"] = 100;
row["NAME"] = $"{row["Name"]}_EditInBranch";
row.Store();
}
}
});
// Delete the feature from the default version
defaultGeodatabase.ApplyEdits(() =>
{
defaultFeatureClass.DeleteRows(queryFilter);
});
// Reconcile options
ReconcileOptions reconcileOptions = new ReconcileOptions(defaultVersion)
{
ConflictResolutionType = ConflictResolutionType.FavorEditVersion,
ConflictDetectionType = ConflictDetectionType.ByRow,
ConflictResolutionMethod = ConflictResolutionMethod.Continue
};
// Reconcile with default
ReconcileResult reconcileResult = editVersion.Reconcile(reconcileOptions);
// Check for conflicts
bool hasConflictsReconcileResults = reconcileResult.HasConflicts;
bool hasConflictsAfterReconcile = editVersion.HasConflicts();
// Fetch conflicts
IReadOnlyList<Conflict> conflictsAfterReconcile = editVersion.GetConflicts();
// Iterate conflicts
foreach (Conflict conflict in conflictsAfterReconcile)
{
// Object ID of row where conflict occurs
long objectId = conflict.ObjectID;
ConflictType conflictType = conflict.ConflictType;
IReadOnlyList<FieldValue> ancestorVersionValues = conflict.AncestorVersionValues;
object nameAncestor = ancestorVersionValues.FirstOrDefault(f => f.FieldName.Contains("NAME")).Value;
object treeAgeAncestor =
ancestorVersionValues.FirstOrDefault(f => f.FieldName.Contains("TREEAGE")).Value;
IReadOnlyList<FieldValue> childVersionValues = conflict.ChildVersionValues;
object nameChild = childVersionValues.FirstOrDefault(f => f.FieldName.Contains("NAME")).Value;
object treeAgeChild = childVersionValues.FirstOrDefault(f => f.FieldName.Contains("TREEAGE")).Value;
IReadOnlyList<FieldValue> parentVersionValues = conflict.ParentVersionValues;
IReadOnlyList<Field> originalFields = defaultFeatureClassDefinition.GetFields();
string datasetName = conflict.DatasetName;
}
}
}
});
}
{
Task ValidateContingentValuesAsync(FeatureClass parcels, string zoningFieldName = "Zone", string taxCodeFieldName = "TaxCode") => QueuedTask.Run(() =>
{
using (RowBuffer rowBuffer = parcels.CreateRowBuffer())
{
// Insert values in a row buffer
rowBuffer[zoningFieldName] = "Business";
rowBuffer[taxCodeFieldName] = "TaxB";
// Validate contingency values of the parcels' row
ContingencyValidationResult contingencyValidationResult = parcels.ValidateContingencies(rowBuffer);
// Valid contingencies
IReadOnlyList<Contingency> matchedContingencies = contingencyValidationResult.Matches;
if (matchedContingencies.Count > 0)
{
// Create a row with valid contingency values
parcels.CreateRow(rowBuffer);
}
// Invalid contingencies
IReadOnlyList<ContingencyViolation> violatedContingencies = contingencyValidationResult.Violations;
foreach (ContingencyViolation contingencyViolation in violatedContingencies)
{
ContingencyViolationType violationType = contingencyViolation.Type;
Contingency violatedContingency = contingencyViolation.Contingency;
}
}
});
}
{
Task GetPossibleContingentValuesAsync(FeatureClass parcels, string zoningFieldName = "Zone") => QueuedTask.Run(() =>
{
using (RowBuffer rowBuffer = parcels.CreateRowBuffer())
{
IReadOnlyDictionary<FieldGroup, IReadOnlyList<ContingentValue>> possibleZonings = parcels.GetContingentValues(rowBuffer, zoningFieldName);
IEnumerable<FieldGroup> possibleFieldGroups = possibleZonings.Keys;
foreach (FieldGroup possibleFieldGroup in possibleFieldGroups)
{
IReadOnlyList<ContingentValue> possibleZoningValues = possibleZonings[possibleFieldGroup];
foreach (ContingentValue possibleZoningValue in possibleZoningValues)
{
switch (possibleZoningValue)
{
case ContingentCodedValue codedValue:
string codedValueDomainName = codedValue.Name;
object codedValueDomainValue = codedValue.CodedValue;
break;
case ContingentRangeValue rangeValue:
object rangeDomainMaxValue = rangeValue.Max;
object rangeDomainMinValue = rangeValue.Min;
break;
case ContingentAnyValue contingentAnyValue:
// Any value type
break;
case ContingentNullValue contingentNullValue:
// Null value
break;
}
}
}
}
});
}
{
await QueuedTask.Run(() =>
{
string message = String.Empty;
bool creationResult = false;
EditOperation editOperation = new EditOperation();
using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
using (Table enterpriseTable = geodatabase.OpenDataset<Table>("LocalGovernment.GDB.piCIPCost"))
{
// Declare the callback here. We are not executing it .yet.
editOperation.Callback(context =>
{
TableDefinition tableDefinition = enterpriseTable.GetDefinition();
int assetNameIndex = tableDefinition.FindField("ASSETNA");
using (RowBuffer rowBuffer = enterpriseTable.CreateRowBuffer())
{
// Either the field index or the field name can be used in the indexer.
rowBuffer[assetNameIndex] = "wMain";
rowBuffer["COST"] = 700;
rowBuffer["ACTION"] = "Open Cut";
// subtype value for "Abandon".
rowBuffer[tableDefinition.GetSubtypeField()] = 3;
using (Row row = enterpriseTable.CreateRow(rowBuffer))
{
// To Indicate that the attribute table has to be updated.
context.Invalidate(row);
}
}
}, enterpriseTable);
try
{
creationResult = editOperation.Execute();
if (!creationResult)
{
message = editOperation.ErrorMessage;
}
}
catch (GeodatabaseException exObj)
{
message = exObj.Message;
}
}
if (!string.IsNullOrEmpty(message))
{
Debug.WriteLine(message);
}
});
}
{
await QueuedTask.Run(() =>
{
string message = String.Empty;
bool creationResult = false;
using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
using (FeatureClass enterpriseFeatureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.FacilitySite"))
{
//Declare the callback here. We are not executing it yet
EditOperation editOperation = new EditOperation();
editOperation.Callback(context =>
{
FeatureClassDefinition facilitySiteDefinition = enterpriseFeatureClass.GetDefinition();
int facilityIdIndex = facilitySiteDefinition.FindField("FACILITYID");
using (RowBuffer rowBuffer = enterpriseFeatureClass.CreateRowBuffer())
{
// Either the field index or the field name can be used in the indexer.
rowBuffer[facilityIdIndex] = "wMain";
rowBuffer["NAME"] = "Griffith Park";
rowBuffer["OWNTYPE"] = "Municipal";
rowBuffer["FCODE"] = "Park";
// Add it to Attractions Subtype.
rowBuffer[facilitySiteDefinition.GetSubtypeField()] = 820;
List<Coordinate2D> newCoordinates = new List<Coordinate2D>
{
new Coordinate2D(1021570, 1880583),
new Coordinate2D(1028730, 1880994),
new Coordinate2D(1029718, 1875644),
new Coordinate2D(1021405, 1875397)
};
rowBuffer[facilitySiteDefinition.GetShapeField()] = new PolygonBuilderEx(newCoordinates).ToGeometry();
using (Feature feature = enterpriseFeatureClass.CreateRow(rowBuffer))
{
//To Indicate that the attribute table has to be updated
context.Invalidate(feature);
}
}
}, enterpriseFeatureClass);
try
{
creationResult = editOperation.Execute();
if (!creationResult)
{
message = editOperation.ErrorMessage;
}
}
catch (GeodatabaseException exObj)
{
message = exObj.Message;
}
}
if (!string.IsNullOrEmpty(message))
{
Debug.WriteLine(message);
}
});
}
{
Task WriteBlobFieldAsync(Table table, string blobFieldName, string imageFileName) => QueuedTask.Run(() =>
{
// Read the image file into a MemoryStream
MemoryStream memoryStream = new MemoryStream();
using (FileStream imageFile = new FileStream(imageFileName, FileMode.Open, FileAccess.Read))
{
imageFile.CopyTo(memoryStream);
}
// Create a new row in the table, and write the Memory Stream into a blob fiele
using (RowBuffer rowBuffer = table.CreateRowBuffer())
{
rowBuffer[blobFieldName] = memoryStream;
table.CreateRow(rowBuffer).Dispose();
}
});
}
{
await QueuedTask.Run(() =>
{
using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file"))))
using (RelationshipClass relationshipClass = geodatabase.OpenDataset<RelationshipClass>("LocalGovernment.GDB.OverviewToProject"))
using (FeatureClass projectsFeatureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.CIPProjects"))
using (FeatureClass overviewFeatureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.CIPProjectsOverview"))
{
// This will be PROJNAME. This can be used to get the field index or used directly as the field name.
string originKeyField = relationshipClass.GetDefinition().GetOriginKeyField();
EditOperation editOperation = new EditOperation();
editOperation.Callback(context =>
{
// The rows are being added to illustrate adding relationships.
// If one has existing rows, those can be used to add a relationship.
using (RowBuffer projectsRowBuffer = projectsFeatureClass.CreateRowBuffer())
using (RowBuffer overviewRowBuffer = overviewFeatureClass.CreateRowBuffer())
{
projectsRowBuffer["TOTCOST"] = 500000;
overviewRowBuffer[originKeyField] = "LibraryConstruction";
overviewRowBuffer["PROJECTMAN"] = "John Doe";
overviewRowBuffer["FUNDSOUR"] = " ";
using (Row projectsRow = projectsFeatureClass.CreateRow(projectsRowBuffer))
using (Row overviewRow = overviewFeatureClass.CreateRow(overviewRowBuffer))
{
Relationship relationship = relationshipClass.CreateRelationship(overviewRow, projectsRow);
//To Indicate that the Map has to draw this feature/row and/or the attribute table has to be updated
context.Invalidate(projectsRow);
context.Invalidate(overviewRow);
context.Invalidate(relationshipClass);
}
}
}, projectsFeatureClass, overviewFeatureClass);
bool editResult = editOperation.Execute();
}
});
}
{
// Insert Cursors are intended for use in CoreHost applications, not Pro Add-ins
await QueuedTask.Run(() =>
{
using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file"))))
using (Table citiesTable = geodatabase.OpenDataset<Table>("name\\of\\cities_table"))
{
geodatabase.ApplyEdits(() =>
{
using (InsertCursor insertCursor = citiesTable.CreateInsertCursor())
using (RowBuffer rowBuffer = citiesTable.CreateRowBuffer())
{
rowBuffer["State"] = "Colorado";
rowBuffer["Name"] = "Fort Collins";
rowBuffer["Population"] = 167830;
insertCursor.Insert(rowBuffer);
rowBuffer["Name"] = "Denver";
rowBuffer["Population"] = 727211;
insertCursor.Insert(rowBuffer);
// Insert more rows here
// A more realistic example would be reading source data from a file
insertCursor.Flush();
}
});
}
});
}
{
Task CreatingAnAnnotationFeatureAsync(Geodatabase geodatabase) => QueuedTask.Run(() =>
{
using (AnnotationFeatureClass annotationFeatureClass = geodatabase.OpenDataset<AnnotationFeatureClass>("Annotation // feature // class // name"))
using (AnnotationFeatureClassDefinition annotationFeatureClassDefinition = annotationFeatureClass.GetDefinition())
using (RowBuffer rowBuffer = annotationFeatureClass.CreateRowBuffer())
using (AnnotationFeature annotationFeature = annotationFeatureClass.CreateRow(rowBuffer))
{
annotationFeature.SetAnnotationClassID(0);
annotationFeature.SetStatus(AnnotationStatus.Placed);
// Get the annotation labels from the label collection
IReadOnlyList<CIMLabelClass> labelClasses =
annotationFeatureClassDefinition.GetLabelClassCollection();
// Setup the symbol reference with the symbol id and the text symbol
CIMSymbolReference cimSymbolReference = new CIMSymbolReference();
cimSymbolReference.Symbol = labelClasses[0].TextSymbol.Symbol;
cimSymbolReference.SymbolName = labelClasses[0].TextSymbol.SymbolName;
// Setup the text graphic
CIMTextGraphic cimTextGraphic = new CIMTextGraphic();
cimTextGraphic.Text = "Charlotte, North Carolina";
cimTextGraphic.Shape = new MapPointBuilderEx(new Coordinate2D(-80.843, 35.234), SpatialReferences.WGS84)
.ToGeometry();
cimTextGraphic.Symbol = cimSymbolReference;
// Set the symbol reference on the graphic and store
annotationFeature.SetGraphic(cimTextGraphic);
annotationFeature.Store();
}
});
}
{
static void ValidateTopology()
{
using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\TestData\GrandTeton.gdb"))))
using (ArcGIS.Core.Data.Topology.Topology topology = geodatabase.OpenDataset<ArcGIS.Core.Data.Topology.Topology>("Backcountry_Topology"))
{
// If the topology currently does not have dirty areas, calling Validate() returns an empty envelope.
ValidationResult result = topology.Validate(new ValidationDescription(topology.GetExtent()));
Console.WriteLine($"'AffectedArea' after validating a topology that has not been edited => {result.AffectedArea.ToJson()}");
// Now create a feature that purposely violates the "PointProperlyInsideArea" topology rule. This action will
// create dirty areas.
Feature newFeature = null;
try
{
// Fetch the feature in the Campsites feature class whose objectID is 2. Then create a new geometry slightly
// altered from this and use it to create a new feature.
using (Feature featureViaCampsites2 = GetFeature(geodatabase, "Campsites", 2))
{
Geometry currentGeometry = featureViaCampsites2.GetShape();
Geometry newGeometry = GeometryEngine.Instance.Move(currentGeometry, (currentGeometry.Extent.XMax / 8), (currentGeometry.Extent.YMax / 8));
using (FeatureClass campsitesFeatureClass = featureViaCampsites2.GetTable())
using (FeatureClassDefinition definition = campsitesFeatureClass.GetDefinition())
using (RowBuffer rowBuffer = campsitesFeatureClass.CreateRowBuffer())
{
rowBuffer[definition.GetShapeField()] = newGeometry;
geodatabase.ApplyEdits(() => { newFeature = campsitesFeatureClass.CreateRow(rowBuffer); });
}
}
// After creating a new feature in the 'Campsites' participating feature class, the topology's state should be
// "Unanalyzed" because it has not been validated.
Console.WriteLine($"The topology state after an edit has been applied => {topology.GetState()}");
// Now validate the topology. The result envelope corresponds to the dirty areas.
result = topology.Validate(new ValidationDescription(topology.GetExtent()));
Console.WriteLine($"'AffectedArea' after validating a topology that has just been edited => {result.AffectedArea.ToJson()}");
// After Validate(), the topology's state should be "AnalyzedWithErrors" because the topology currently has errors.
Console.WriteLine($"The topology state after validate topology => {topology.GetState()}");
// If there are no dirty areas, the result envelope should be empty.
result = topology.Validate(new ValidationDescription(topology.GetExtent()));
Console.WriteLine($"'AffectedArea' after validating a topology that has just been validated => {result.AffectedArea.ToJson()}");
}
finally
{
if (newFeature != null)
{
geodatabase.ApplyEdits(() => { newFeature.Delete(); });
newFeature.Dispose();
}
}
// Validate again after deleting the newly-created feature.
topology.Validate(new ValidationDescription(topology.GetExtent()));
}
}
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)