ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Editing Namespace / EditOperation Class / Modify Method / Modify(Layer,Int64,Geometry,Dictionary<String,Object>) Method
The layer of the feature to modify.
The oid of the feature to modify.
The geometry to update on the feature.
(Optional). The attribute values to update on the feature (by field Name).
Example

In This Topic
    Modify(Layer,Int64,Geometry,Dictionary<String,Object>) Method
    In This Topic
    Modify a feature, updating the geometry and attribute values.
    Syntax
    Public Overloads Sub Modify( _
       ByVal layer As Layer, _
       ByVal oid As Long, _
       ByVal geometry As Geometry, _
       Optional ByVal attributes As Dictionary(Of String,Object) _
    ) 

    Parameters

    layer
    The layer of the feature to modify.
    oid
    The oid of the feature to modify.
    geometry
    The geometry to update on the feature.
    attributes
    (Optional). The attribute values to update on the feature (by field Name).
    Example
    Edit Operation - check for actions before Execute
    // Checks for pending actions in an edit operation before attempting to execute it.
    await QueuedTask.Run(() =>
    {
      // Create an edit operation
      var op = new EditOperation() { Name = "My Edit Operation" };
      // Add some actions to the edit operation
      op.Modify(featureLayer, objectId, geometry);
      // EditOperation.Modify can unknowingly set an attribute to the already existing value
      // In this scenario the Modify action will detect that no changes are required and consequently the Execute operation will fail.
      // To avoid this, we can check if the edit operation is empty before executing it.
      if (!op.IsEmpty)
      {
        // Execute the edit operation
        var result = op.Execute();
        Debug.WriteLine($"Edit operation executed successfully: {result}");
      }
      else
      {
        Debug.WriteLine("No actions to execute in the edit operation.");
      }
    });
    Edit Operation Duplicate Features
    // 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();
            }
          }
        }
      });
    Edit Operation Modify single feature
    // Modifies a single feature in the specified feature layer.
    await QueuedTask.Run(() =>
      {
        var modifyFeature = new EditOperation() { Name = "Modify a feature" };
    
        //use an inspector
        var modifyInspector = new Inspector();
        modifyInspector.Load(featureLayer, objectId);//base attributes on an existing feature
    
        //change attributes for the new feature
        modifyInspector["SHAPE"] = polygon;//Update the geometry
        modifyInspector["NAME"] = "Updated name";//Update attribute(s)
    
        modifyFeature.Modify(modifyInspector);
    
        //update geometry and attributes using overload
        var featureAttributes = new Dictionary<string, object>
        {
          ["NAME"] = "Updated name"//Update attribute(s)
        };
        modifyFeature.Modify(featureLayer, objectId, polygon, featureAttributes);
    
        //Execute to execute the operation
        //Must be called within QueuedTask.Run
        if (!modifyFeature.IsEmpty)
        {
          //Execute and ExecuteAsync will return true if the operation was successful and false if not
          var result = modifyFeature.Execute();
          //or use async flavor
          //await modifyFeatures.ExecuteAsync();
        }
      });
    Move feature to a specific coordinate
    // Moves the first selected feature in the specified feature layer to the given coordinates.
    await QueuedTask.Run<bool>(() =>
     {
       //Get all of the selected ObjectIDs from the layer.
       var mySelection = featureLayer.GetSelection();
       var selOid = mySelection.GetObjectIDs()?[0];
       var xCoordinate = 0.0;
       var yCoordinate = 0.0; // specify the target coordinates to move the geometry
       var moveToPoint = new MapPointBuilderEx(xCoordinate, yCoordinate, 0.0, 0.0, featureLayer.GetSpatialReference());
    
       var moveEditOperation = new EditOperation() { Name = "Move features" };
       moveEditOperation.Modify(featureLayer, selOid ?? -1, moveToPoint.ToGeometry());  //Modify the feature to the new geometry
       if (!moveEditOperation.IsEmpty)
       {
         var result = moveEditOperation.Execute(); //Execute and ExecuteAsync will return true if the operation was successful and false if not
         return result; // return the operation result: true if successful, false if not
       }
       return false; // return false to indicate that the operation was not empty
     });
    Convert vertices in a polyline to a Control Point
    //Control points are special vertices used to apply symbol effects to line or polygon features.
      //By default, they appear as diamonds when you edit them.
      //They can also be used to migrate representations from ArcMap to features in ArcGIS Pro.
      await QueuedTask.Run(() =>
      {
        var changeVertexIDOperation = new EditOperation();
        //iterate through the points in the polyline.
        var lineLayerCursor = lineLayer.GetSelection().Search();
        var lineVertices = new List<MapPoint>();
        long objectId = -1;
        while (lineLayerCursor.MoveNext())
        {
          var lineFeature = lineLayerCursor.Current as ArcGIS.Core.Data.Feature;
          var line = lineFeature.GetShape() as Polyline;
          int vertexIndex = 1;
          objectId = lineFeature.GetObjectID();
          //Each point is converted into a MapPoint and gets added to a list.
          foreach (var point in line.Points)
          {
            MapPointBuilderEx mapPointBuilderEx = new(point);
            //Changing the vertex 6 and 7 to control points
            if (vertexIndex == 6 || vertexIndex == 7)
            {
              //These points are made "ID Aware" and the IDs are set to be 1.
              mapPointBuilderEx.HasID = true;
              mapPointBuilderEx.ID = 1;
            }
    
            lineVertices.Add(mapPointBuilderEx.ToGeometry() as MapPoint);
            vertexIndex++;
          }
        }
        //create a new polyline using the point collection.
        var newLine = PolylineBuilderEx.CreatePolyline(lineVertices);
        //edit operation to modify the original line with the new line that contains control points.
        changeVertexIDOperation.Modify(lineLayer, objectId, newLine);
        changeVertexIDOperation.Execute();
      });
    }
    Order edits sequentially
    // Modifies the "NAME" attribute of a specified feature and then splits the feature using the provided polyline, all within a single sequential edit operation.
    // perform an edit and then a split as one operation.
    await QueuedTask.Run(() =>
     {
       var newName = "Modified then Split";
       var queryFilter = new QueryFilter() { WhereClause = "OBJECTID = " + objectId.ToString() };
    
       // create an edit operation and name.
       var op = new EditOperation
       {
         Name = "modify followed by split",         // set the ExecuteMode
         ExecuteMode = ExecuteModeType.Sequential
       };
       using (var rowCursor = layer.Search(queryFilter))
       {
         while (rowCursor.MoveNext())
         {
           using var feature = rowCursor.Current as ArcGIS.Core.Data.Feature;
           op.Modify(feature, "NAME", newName);
         }
       }
       op.Split(layer, objectId, splitLine);
       if (!op.IsEmpty)
       {
         bool result = op.Execute();
       }
       // else
       //  The operation doesn't make any changes to the database so if executed it will fail
     });
    Read and Write blob fields with the attribute inspector
    await QueuedTask.Run(() =>
    {
      // get selected feature into inspector
      var selectedFeatures = activeMap.GetSelection();
      var insp = new Inspector();
      insp.Load(selectedFeatures.ToDictionary().Keys.First(), selectedFeatures.ToDictionary().Values.First());
      // read a blob field and save to a file
      var msw = new MemoryStream();
      msw = insp["BlobField"] as MemoryStream;
      using (FileStream file = new(@"d:\temp\blob.jpg", FileMode.Create, FileAccess.Write))
      {
        msw.WriteTo(file);
      }
      // read file into memory stream
      var msr = new MemoryStream();
      using (FileStream file = new(@"d:\images\Hydrant.jpg", FileMode.Open, FileAccess.Read))
      {
        file.CopyTo(msr);
      }
      //put the memory stream in the blob field and save to feature
      var op = new EditOperation() { Name = "Blob Inspector" };
      insp["Blobfield"] = msr;
      op.Modify(insp);
      if (!op.IsEmpty)
      {
        var result = op.Execute(); //Execute and ExecuteAsync will return true if the operation was successful and false if not
      }
    });
    Write a compressed image to a raster field
    var compressedRasterMapView = MapView.Active;
    if (compressedRasterMapView == null)
      return;
    
    await QueuedTask.Run(() =>
    {
      //Open the raster dataset on disk and create a compressed raster value dataset object
      var dataStore = new ArcGIS.Core.Data.FileSystemDatastore(new ArcGIS.Core.Data.FileSystemConnectionPath(new Uri(@"e:\temp"), ArcGIS.Core.Data.FileSystemDatastoreType.Raster));
      using (var fileRasterDataset = dataStore.OpenDataset<ArcGIS.Core.Data.Raster.RasterDataset>("Hydrant.jpg"))
      {
        var storageDef = new ArcGIS.Core.Data.Raster.RasterStorageDef();
        storageDef.SetCompressionType(ArcGIS.Core.Data.Raster.RasterCompressionType.JPEG);
        storageDef.SetCompressionQuality(90);
    
        var rv = new ArcGIS.Core.Data.Raster.RasterValue();
        rv.SetRasterDataset(fileRasterDataset);
        rv.SetRasterStorageDef(storageDef);
    
        var sel = compressedRasterMapView.Map.GetSelection();
    
        //insert a raster value object into the raster field
        var insp = new ArcGIS.Desktop.Editing.Attributes.Inspector();
        insp.Load(sel.ToDictionary().Keys.First(), sel.ToDictionary().Values.First());
        insp["Photo"] = rv;
    
        var op = new EditOperation() { Name = "Raster Inspector" };
        op.Modify(insp);
        if (!op.IsEmpty)
        {
          var result = op.Execute(); //Execute and ExecuteAsync will return true if the operation was successful and false if not
        }
      }
    });
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also