ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Data Namespace / Feature Class / SetShape Method
The geometry of this feature.
Example

In This Topic
    SetShape Method
    In This Topic
    Sets the geometry of this feature. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Sub SetShape( _
       ByVal shape As Geometry _
    ) 
    public void SetShape( 
       Geometry shape
    )

    Parameters

    shape
    The geometry of this feature.
    Exceptions
    ExceptionDescription
    This feature's type of shape (i.e., geometry) is not supported.
    A geodatabase-related exception has occurred.
    Example
    Modifying a Feature
    {
      await QueuedTask.Run(() =>
      {
        string message = String.Empty;
        bool modificationResult = false;
    
        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
        using (FeatureClass enterpriseFeatureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.FacilitySite"))
        {
          FeatureClassDefinition facilitySiteDefinition = enterpriseFeatureClass.GetDefinition();
    
          int ownTypeIndex = facilitySiteDefinition.FindField("OWNTYPE");
          int areaIndex = facilitySiteDefinition.FindField(facilitySiteDefinition.GetAreaField());
    
          EditOperation editOperation = new EditOperation();
          editOperation.Callback(context =>
          {
            QueryFilter queryFilter = new QueryFilter
            { WhereClause = "FCODE = 'Hazardous Materials Facility' AND OWNTYPE = ' '" };
    
            using (RowCursor rowCursor = enterpriseFeatureClass.Search(queryFilter, false))
            {
              while (rowCursor.MoveNext())
              {
                using (Feature feature = (Feature)rowCursor.Current)
                {
                  // In order to update the Map and/or the attribute table.
                  // Has to be called before any changes are made to the row
                  context.Invalidate(feature);
    
                  // Transfer all Hazardous Material Facilities to the City.
                  feature[ownTypeIndex] = "Municipal";
    
                  if (Convert.ToDouble(feature[areaIndex]) > 50000)
                  {
                    // Set the Shape of the feature to whatever you need.
                    List<Coordinate2D> newCoordinates = new List<Coordinate2D>
                    {
                        new Coordinate2D(1021570, 1880583),
                        new Coordinate2D(1028730, 1880994),
                        new Coordinate2D(1029718, 1875644),
                        new Coordinate2D(1021405, 1875397)
                    };
    
                    feature.SetShape(new PolygonBuilderEx(newCoordinates).ToGeometry());
                  }
    
                  feature.Store();
    
                  // Has to be called after the store too
                  context.Invalidate(feature);
                }
              }
            }
          }, enterpriseFeatureClass);
    
          try
          {
            modificationResult = editOperation.Execute();
            if (!modificationResult) message = editOperation.ErrorMessage;
          }
          catch (GeodatabaseException exObj)
          {
            message = exObj.Message;
          }
        }
    
        if (!string.IsNullOrEmpty(message))
          Debug.WriteLine(message);
      });
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also