Hi All,
I am using the following to delete the features in target SDE:
EditOperation editOperation = new EditOperation();
editOperation.Callback(context =>
{
ArcGIS.Core.Data.QueryFilter openCutFilter = new ArcGIS.Core.Data.QueryFilter { WhereClause = "field = 'something'" };
using (RowCursor rowCursor = featureClass.Search(openCutFilter, false))
{
while (rowCursor.MoveNext())
{
using (Row row = rowCursor.Current)
{
// In order to update the Map and/or the attribute table. Has to be called before the delete.
context.Invalidate(row);
row.Delete();
}
}
}
}, featureClass);
After deleting I want to insert all the data from GDB to SDE. How to achieve this?
For data insert, have you looked into the insert cursor?
For further details, please refer to the conceptual doc.
Hi @Aashis thanks for the reply,
EditOperation insertOperation = new EditOperation();
insertOperation.Callback(context =>
{
using (Geodatabase gdb = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri("source.gdb"))))
{
{
// Open the source feature class
using (Table sourceFeatureClass = gdb.OpenDataset<Table>("fcname"))
{
using (InsertCursor insertCursor = featureClass.CreateInsertCursor())
{
// Iterate through the rows in the source feature class
using (RowCursor sourceCursor = sourceFeatureClass.Search())
{
while (sourceCursor.MoveNext())
{
using (Row sourceRow = sourceCursor.Current)
{
Feature feat = (Feature)sourceCursor.Current;
// Create a new row buffer for the target feature class
using (RowBuffer targetRowBuffer = featureClass.CreateRowBuffer())
{
// Copy attribute values from the source to the target
foreach (ArcGIS.Core.Data.Field sourceField in sourceFeatureClass.GetDefinition().GetFields())
{
string fieldName = sourceField.Name;
if (featureClass.GetDefinition().GetFields().Any(f => f.Name == fieldName))
{
// Check if the field is writable
if (featureClass.GetDefinition().GetFields().First(f => f.Name == fieldName).IsEditable)
{
// Set attribute value in the target row buffer
targetRowBuffer[fieldName] = sourceRow[fieldName];
}
else
{
// Handle non-writable field (e.g., log a message or skip)
Console.WriteLine($"Field '{fieldName}' is not writable.");
}
}
}
// Insert the new row into the target feature class
insertCursor.Insert(targetRowBuffer);
}
}
}
}
// Flush the insert cursor to commit the changes
insertCursor.Flush();
}
}
}
}
}, featureClass);
I am using the above code copy from source feature class to target but it is not inserting all fields. Can you help with inserting all fields from source to SDE?
ArcGIS works with specific database management systems (DBMS) data types. Depending on the DBMS type, a field's precision, scale, or geometry type (Geometry vs ST_Geometry) may change. Some DBMSs don't support the field types that exist in another DBMS.
File and mobile geodatabase data types are the same as ArcGIS data types. For DBMS, ArcGIS data types map to database data types and can differ depending on the DBMS. Here is the mapping table of supported field data types for each DBMS. Users should be responsible for creating a properly mapped schema before migrating data.
With this mapping information, could you please tell us which field values/types are not copied from one environment to another?
@Aashis Thanks for the reply. I am to insert now by following code :
foreach (var sourceField in sourceFeature.GetFields())
{
if (sourceField.Name == sourceFeatureClass.GetDefinition().GetObjectIDField())
{
continue;
}
// Find the corresponding field in the target feature class
int targetFieldIndex = targetFeatureDefinition.FindField(sourceField.Name);
// If the field exists in the target feature class
if (targetFieldIndex >= 0)
{
// Get the value of the field from the source feature
var value = sourceFeature[sourceField.Name];
//targetRowBuffer[targetFeatureDefinition.GetShapeField()] = featureGeometry;
// Set the value in the target row buffer
targetRowBuffer_i[targetFieldIndex] = value;
}
}