ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Editing.Attributes Namespace / Inspector Class / Load Method / Load(MapMember,Int64) Method
mapMember
object ID
Example

In This Topic
    Load(MapMember,Int64) Method
    In This Topic
    Load a single row or feature into the inspector. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public void Load( 
       MapMember member,
       long oid
    )
    Public Overloads Sub Load( _
       ByVal member As MapMember, _
       ByVal oid As Long _
    ) 

    Parameters

    member
    mapMember
    oid
    object ID
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Example
    Create feature from a modified inspector
    // 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
          }
        });
    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 Merge Features
    // Merges multiple features from a source feature layer into a new feature, optionally using a template or inspector, and supports merging into a destination layer.
    await QueuedTask.Run(() =>
    {
      var mergeFeatures = new EditOperation() { Name = "Merge Features" };
    
      //Merge three features into a new feature using defaults
      //defined in the current template
      mergeFeatures.Merge(currentTemplate as EditingRowTemplate, featureLayer, [10, 96, 12]);
    
      //Merge three features into a new feature in the destination layer
      mergeFeatures.Merge(destinationLayer, featureLayer, [10, 96, 12]);
    
      //Use an inspector to set the new attributes of the merged feature
      var inspector = new Inspector();
      inspector.Load(featureLayer, objectId);//base attributes on an existing feature
      inspector["NAME"] = "New name";
      inspector["DESCRIPTION"] = "New description";
    
      //Merge features into a new feature in the same layer using the
      //defaults set in the inspector
      mergeFeatures.Merge(featureLayer, [10, 96, 12], inspector);
    
      //Execute to execute the operation
      //Must be called within QueuedTask.Run
      if (!mergeFeatures.IsEmpty)
      {
        //Execute and ExecuteAsync will return true if the operation was successful and false if not
        var result = mergeFeatures.Execute();
        //or use async flavor
        //await mergeFeatures.ExecuteAsync();
      }
    });
    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();
        }
      });
    Update Annotation Text
    // Updates the text of an annotation feature in the specified annotation layer.
    await QueuedTask.Run(() =>
    {
      // annotationLayer is ~your~ Annotation layer...
      // use the inspector methodology
      var insp = new Inspector();
      insp.Load(annotationLayer, objectId);
      // get the annotation properties
      AnnotationProperties annoProperties = insp.GetAnnotationProperties();
      // set the attribute
      annoProperties.TextString = annotationText;
      // assign the annotation properties 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
    // Modifies the geometry of an annotation feature in the specified annotation layer.
    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(annotationLayer, objectId);
      //var shape = insp["SHAPE"] as Polygon;
      //...wrong shape...
      //Instead, we must use the AnnotationProperties
      //annotationLayer is ~your~ Annotation layer
      var insp = new Inspector();
      insp.Load(annotationLayer, objectId);
      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
        {
          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
    // Modifies the text graphic of a selected annotation feature in the specified annotation layer.
    await QueuedTask.Run(() =>
    {
      var selection = annotationLayer.GetSelection();
      if (selection.GetCount() == 0)
      {
        return;
      }
      // use the first selected feature
      var insp = new Inspector();
      insp.Load(annotationLayer, 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
      {
        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.
    {
      var oid = 1;
    
      // See "Change Annotation Text Graphic" for an alternative if TEXTSTRING is missing from the schema
    
      await QueuedTask.Run(() =>
      {
        // use the inspector methodology
        var insp = new Inspector();
        insp.Load(annotationLayer, 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(annotationLayer, oid, newAtts);
    
          op.Execute();
        }
      });
    }
    Edit the attributes of a FeatureSceneLayer
    {
      //must support editing!
      if (!featSceneLayer.HasAssociatedFeatureService ||
          !featSceneLayer.IsEditable)
      {
        return;
      }
    
      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);
        editOp.Execute();//synchronous flavor
      });
    }
    Select features via the MapView
    {
      //assume the geometry used in SelectFeaturesEx() is coming from a
      //map tool...
      //SketchType = SketchGeometryType.Rectangle;
      //SketchOutputMode = SketchOutputMode.Screen;
    
      var mapView = MapView.Active;
      if (mapView == null)
        return;
    
      await QueuedTask.Run(() =>
      {
        var result = mapView.SelectFeaturesEx(geometry);
        //Get scene layers with selections
        var scene_layers = result.ToDictionary<FeatureSceneLayer>();
        foreach (var kvp in scene_layers)
        {
          var scene_layer = kvp.Key as FeatureSceneLayer;
          var sel_oids = kvp.Value;
          //If there are attributes then get them
          if (scene_layer.HasAssociatedFeatureService)
          {
            var insp = new Inspector();
            foreach (var objectid in sel_oids)
            {
              insp.Load(scene_layer, objectid);
              //TODO something with retrieved attributes
            }
          }
        }
      });
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also