// Creates a new feature by copying and optionally modifying the attributes of an existing feature using an inspector. await QueuedTask.Run(() => { // Create an inspector and load a feature // The inspector is used to modify the attributes of the feature before creating it var insp = new Inspector(); insp.Load(featureLayer, objectId); // modify attributes if necessary // insp["Field1"] = newValue; //Create new feature from an existing inspector (copying the feature) var createOp = new EditOperation() { Name = "Create from insp" }; createOp.Create(insp.MapMember, insp.ToDictionary(a => a.FieldName, a => a.CurrentValue)); if (!createOp.IsEmpty) { var result = createOp.Execute(); //Execute and ExecuteAsync will return true if the operation was successful and false if not } });
// Duplicates a feature in a feature layer and modifies its geometry. await QueuedTask.Run(() => { var duplicateFeatures = new EditOperation() { Name = "Duplicate Features" }; //Duplicate with an X and Y offset of 500 map units //Execute to execute the operation //Must be called within QueuedTask.Run var insp2 = new Inspector(); insp2.Load(featureLayer, objectId); var geom = insp2["SHAPE"] as Geometry; var rtoken = duplicateFeatures.Create(insp2.MapMember, insp2.ToDictionary(a => a.FieldName, a => a.CurrentValue)); if (!duplicateFeatures.IsEmpty) { if (duplicateFeatures.Execute())//Execute and ExecuteAsync will return true if the operation was successful and false if not { var modifyOp = duplicateFeatures.CreateChainedOperation(); modifyOp.Modify(featureLayer, (long)rtoken.ObjectID, GeometryEngine.Instance.Move(geom, 500.0, 500.0)); if (!modifyOp.IsEmpty) { var result = modifyOp.Execute(); } } } });
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)