ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Editing Namespace / EditOperation Class / Create Method / Create(MapMember,Dictionary<String,Object>) Method
The layer or standalone table to create the new row in.
The attributes to assign to the new row.
Example

In This Topic
    Create(MapMember,Dictionary<String,Object>) Method
    In This Topic
    Creates a new row with the given attributes.
    Syntax

    Parameters

    mapMember
    The layer or standalone table to create the new row in.
    values
    The attributes to assign to the new row.

    Return Value

    A RowToken object that represents the row to be created.
    Example
    Edit Operation Create Features
    var createFeatures = new EditOperation() { Name = "Create Features" };
    //Create a feature with a polygon
    var token = createFeatures.Create(featureLayer, polygon);
    if (createFeatures.IsSucceeded)
    {
      // token.ObjectID wll be populated with the objectID of the created feature after Execute has been successful
    }
    //Do a create features and set attributes
    var attributes = new Dictionary<string, object>();
    attributes.Add("SHAPE", polygon);
    attributes.Add("NAME", "Corner Market");
    attributes.Add("SIZE", 1200.5);
    attributes.Add("DESCRIPTION", "Corner Market");
    
    createFeatures.Create(featureLayer, attributes);
    
    //Create features using the current template
    //Must be within a MapTool
    createFeatures.Create(this.CurrentTemplate, polygon);
    
    //Execute to execute the operation
    //Must be called within QueuedTask.Run
    
    if (!createFeatures.IsEmpty)
    {
      createFeatures.Execute(); //Execute will return true if the operation was successful and false if not.
    }
    
    //or use async flavor
    //await createFeatures.ExecuteAsync();
    
    Create feature from a modified inspector
    var insp = new ArcGIS.Desktop.Editing.Attributes.Inspector();
    insp.Load(layer, 86);
    
    ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
    {
      // 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
      }
    });
    Create features from a CSV file
    //Run on MCT
    ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
    {
      //Create the edit operation
      var createOperation = new ArcGIS.Desktop.Editing.EditOperation() { Name = "Generate points", SelectNewFeatures = false };
    
      // determine the shape field name - it may not be 'Shape' 
      string shapeField = layer.GetFeatureClass().GetDefinition().GetShapeField();
    
      //Loop through csv data
      foreach (var item in csvData)
      {
    
        //Create the point geometry
        ArcGIS.Core.Geometry.MapPoint newMapPoint =
            ArcGIS.Core.Geometry.MapPointBuilderEx.CreateMapPoint(item.X, item.Y);
    
        // include the attributes via a dictionary
        var atts = new Dictionary<string, object>();
        atts.Add("StopOrder", item.StopOrder);
        atts.Add("FacilityID", item.FacilityID);
        atts.Add(shapeField, newMapPoint);
    
        // queue feature creation
        createOperation.Create(layer, atts);
      }
    
      // execute the edit (feature creation) operation
      if (createOperation.IsEmpty)
      {
        return createOperation.Execute(); //Execute and ExecuteAsync will return true if the operation was successful and false if not
      }
      else
        return false;
    });
    Edit Operation Duplicate Features
    {
      var duplicateFeatures = new EditOperation() { Name = "Duplicate Features" };
    
      //Duplicate with an X and Y offset of 500 map units
      //At 2.x duplicateFeatures.Duplicate(featureLayer, oid, 500.0, 500.0, 0.0);
    
      //Execute to execute the operation
      //Must be called within QueuedTask.Run
      var insp2 = new Inspector();
      insp2.Load(featureLayer, oid);
      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();
          }
        }
      }
    }
    
    Create a new Entity
    await QueuedTask.Run(() =>
    {
    
      //Instantiate an operation for the Create
      var edit_op = new EditOperation()
      {
        Name = "Create a new organization",
        SelectNewFeatures = true
      };
    
      //Use datasets or feature layer(s) or standalone table(s)
      //Get a reference to the KnowledgeGraph
      //var kg = ... ; 
    
      //Open the feature class or Table to be edited
      var org_fc = kg.OpenDataset<FeatureClass>("Organization");
    
      //Alternatively, use the feature layer for 'Organization' if your context is a map
      //Get the parent KnowledgeGraphLayer
      var kg_layer = mv.Map.GetLayersAsFlattenedList()?
                    .OfType<ArcGIS.Desktop.Mapping.KnowledgeGraphLayer>().First();
      //From the KG Layer get the relevant child feature layer
      var org_fl = kg_layer.GetLayersAsFlattenedList().OfType<FeatureLayer>()
                      .First(child_layer => child_layer.Name == "Organization");
    
      //Define attributes
      var attribs = new Dictionary<string, object>();
      attribs["Name"] = "Acme Ltd.";
      attribs["Description"] = "Specializes in household items";
      attribs["SHAPE"] = org_location;
    
      //Add it to the operation via the dataset...
      edit_op.Create(org_fc, attribs);
      //or use the feature layer/stand alone table if preferred and available
      //edit_op.Create(org_fl, attribs);
    
      if (edit_op.Execute())
      {
        //TODO: Operation succeeded
      }
    
    });
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also