ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Editing Namespace / EditOperation Class / Modify Method / Modify(Inspector) Method
An inspector that specifies the features or rows and their attributes.
Example

In This Topic
    Modify(Inspector) Method
    In This Topic
    Modify a feature or row defined by an inspector object.
    Syntax
    public void Modify( 
       Inspector inspector
    )
    Public Overloads Sub Modify( _
       ByVal inspector As Inspector _
    ) 

    Parameters

    inspector
    An inspector that specifies the features or rows and their attributes.
    Exceptions
    ExceptionDescription
    Angle can only be set for Point geometries or Two-point polyline geometries.
    Remarks
    This method is used to update the geometry and/or attribute values of features.
    Example
    Edit Operation Modify single feature
    var modifyFeature = new EditOperation();
    modifyFeature.Name = "Modify a feature";
    
    //use an inspector
    var modifyInspector = new Inspector();
    modifyInspector.Load(featureLayer, oid);//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>();
    featureAttributes["NAME"] = "Updated name";//Update attribute(s)
    modifyFeature.Modify(featureLayer, oid, polygon, featureAttributes);
    
    //Execute to execute the operation
    //Must be called within QueuedTask.Run
    if (!modifyFeature.IsEmpty)
    {
      var result = modifyFeature.Execute(); //Execute and ExecuteAsync will return true if the operation was successful and false if not
    }
    
    //or use async flavor
    //await modifyFeatures.ExecuteAsync();
    
    Edit Operation Modify multiple features
    //Search by attribute
    var queryFilter = new QueryFilter();
    queryFilter.WhereClause = "OBJECTID < 1000000";
    //Create list of oids to update
    var oidSet = new List<long>();
    using (var rc = featureLayer.Search(queryFilter))
    {
      while (rc.MoveNext())
      {
        using (var record = rc.Current)
        {
          oidSet.Add(record.GetObjectID());
        }
      }
    }
    
    //create and execute the edit operation
    var modifyFeatures = new EditOperation();
    modifyFeatures.Name = "Modify features";
    modifyFeatures.ShowProgressor = true;
    
    var muultipleFeaturesInsp = new Inspector();
    muultipleFeaturesInsp.Load(featureLayer, oidSet);
    muultipleFeaturesInsp["MOMC"] = 24;
    modifyFeatures.Modify(muultipleFeaturesInsp);
    if (!modifyFeatures.IsEmpty)
    {
      var result = modifyFeatures.ExecuteAsync(); //Execute and ExecuteAsync will return true if the operation was successful and false if not
    }
    Read and Write blob fields with the attribute inspector
    QueuedTask.Run(() =>
    {
      //get selected feature into inspector
      var selectedFeatures = MapView.Active.Map.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 FileStream(@"d:\temp\blob.jpg", FileMode.Create, FileAccess.Write))
      {
        msw.WriteTo(file);
      }
    
      //read file into memory stream
      var msr = new MemoryStream();
      using (FileStream file = new FileStream(@"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();
      op.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
    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 System.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 = MapView.Active.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();
        op.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
        }
      }
    });
    Update Annotation Text
    await QueuedTask.Run(() =>
    {
      //annoLayer is ~your~ Annotation layer...
    
      // use the inspector methodology
      //at 2.x - var insp = new Inspector(true);
      var insp = new Inspector();
      insp.Load(annoLayer, oid);
    
      // get the annotation properties
      AnnotationProperties annoProperties = insp.GetAnnotationProperties();
      // set the attribute
      annoProperties.TextString = "Hello World";
      // assign the annotation proeprties back to the inspector
      insp.SetAnnotationProperties(annoProperties);
    
      //create and execute the edit operation
      EditOperation op = new EditOperation();
      op.Name = "Update annotation";
      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
      }
    });
    Modify Annotation Shape
    await QueuedTask.Run(() =>
    {
      //Don't use 'Shape'....Shape is the bounding box of the annotation text. This is NOT what you want...
      //
      //var insp = new Inspector();
      //insp.Load(annoLayer, oid);
      //var shape = insp["SHAPE"] as Polygon;
      //...wrong shape...
    
      //Instead, we must use the AnnotationProperties
    
      //annoLayer is ~your~ Annotation layer
      //at 2.x - var insp = new Inspector(true);
      var insp = new Inspector();
      insp.Load(annoLayer, oid);
    
      AnnotationProperties annoProperties = insp.GetAnnotationProperties();
      var shape = annoProperties.Shape;
      if (shape.GeometryType != GeometryType.GeometryBag)
      {
        var newGeometry = GeometryEngine.Instance.Move(shape, 10, 10);
        annoProperties.Shape = newGeometry;
        insp.SetAnnotationProperties(annoProperties);
    
        EditOperation op = new EditOperation();
        op.Name = "Change annotation angle";
        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
        }
      }
    });
    
    Modify Annotation Text Graphic
    await QueuedTask.Run(() =>
    {
    
      var selection = annoLayer.GetSelection();
      if (selection.GetCount() == 0)
        return;
    
      // use the first selelcted feature 
      //at 2.x - var insp = new Inspector(true);
      var insp = new Inspector();
      insp.Load(annoLayer, selection.GetObjectIDs().FirstOrDefault());
    
      // getAnnoProperties should return null if not an annotation feature
      AnnotationProperties annoProperties = insp.GetAnnotationProperties();
      // get the textGraphic
      CIMTextGraphic textGraphic = annoProperties.TextGraphic;
    
      // change text
      textGraphic.Text = "Hello world";
    
      // set x,y offset via the symbol
      var symbol = textGraphic.Symbol.Symbol;
      var textSymbol = symbol as CIMTextSymbol;
      textSymbol.OffsetX = 2;
      textSymbol.OffsetY = 3;
    
      textSymbol.HorizontalAlignment = HorizontalAlignment.Center;
    
      // load the updated textGraphic
      annoProperties.LoadFromTextGraphic(textGraphic);
      // assign the annotation properties back 
      insp.SetAnnotationProperties(annoProperties);
    
      EditOperation op = new EditOperation();
      op.Name = "modify symbol";
      op.Modify(insp);
      if (!op.IsEmpty)
      {
        bool result = op.Execute(); //Execute and ExecuteAsync will return true if the operation was successful and false if not
      }
    });
    
    Update Annotation Text via attribute. Caveat: The TEXTSTRING Anno attribute must exist
    //See "Change Annotation Text Graphic" for an alternative if TEXTSTRING is missing from the schema
    await QueuedTask.Run(() =>
    {
        //annoLayer is ~your~ Annotation layer...
    
        // use the inspector methodology
        var insp = new Inspector();
        insp.Load(annoLayer, oid);
    
        // make sure TextString attribute exists.
        //It is not guaranteed to be in the schema
        ArcGIS.Desktop.Editing.Attributes.Attribute att = insp.FirstOrDefault(a => a.FieldName == "TEXTSTRING");
        if (att != null)
        {
            insp["TEXTSTRING"] = "Hello World";
    
            //create and execute the edit operation
            EditOperation op = new EditOperation();
            op.Name = "Update annotation";
            op.Modify(insp);
    
            //OR using a Dictionary - again TEXTSTRING has to exist in the schema
            //Dictionary<string, object> newAtts = new Dictionary<string, object>();
            //newAtts.Add("TEXTSTRING", "hello world");
            //op.Modify(annoLayer, oid, newAtts);
    
            op.Execute();
        }
    });
    Edit the attributes of a FeatureSceneLayer
    //must support editing!
    var featSceneLayer = MapView.Active.Map.GetLayersAsFlattenedList()
                       .OfType<FeatureSceneLayer>().FirstOrDefault();
    if (!featSceneLayer.HasAssociatedFeatureService || 
        !featSceneLayer.IsEditable)
      return;
    
    var ok = await QueuedTask.Run(() =>
    {
      var editOp = new EditOperation()
      {
        Name = "Edit FeatureSceneLayer Attributes",
        SelectModifiedFeatures = true
      };
      //make an inspector
      var inspector = new Inspector();
      //get the attributes for the specified oid
      inspector.Load(featSceneLayer, oid);
      inspector["PermitNotes"] = "test";//modify
      editOp.Modify(inspector);
      return editOp.Execute();//synchronous flavor
    });
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also