ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Data.DDL Namespace / SchemaBuilder Class / Modify Method / Modify(FeatureClassDescription) Method
Indicates the ArcGIS.Core.Data.FeatureClass to be modified.
Example

In This Topic
    Modify(FeatureClassDescription) Method
    In This Topic
    Enqueue the modify operation on the object referred to by the FeatureClassDescription. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax

    Parameters

    featureClassDescription
    Indicates the ArcGIS.Core.Data.FeatureClass to be modified.
    Exceptions
    ExceptionDescription
    featureClassDescription is null.
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Example
    Adding fields to a FeatureClass
    {
      // Must be called within QueuedTask.Run
      void AddFieldsInFeatureClassSnippet(Geodatabase geodatabase)
      {
        // Adding following fields to the 'Parcels' FeatureClass
        // Global ID
        // Parcel_ID
        // Tax_Code
        // Parcel_Address
    
        // The FeatureClass to add fields
        string featureClassName = "Parcels";
    
        FeatureClassDefinition originalFeatureClassDefinition = geodatabase.GetDefinition<FeatureClassDefinition>(featureClassName);
        FeatureClassDescription originalFeatureClassDescription = new FeatureClassDescription(originalFeatureClassDefinition);
    
        // The four new fields to add on the 'Parcels' FeatureClass
        FieldDescription globalIdField = FieldDescription.CreateGlobalIDField();
        FieldDescription parcelIdDescription = new FieldDescription("Parcel_ID", FieldType.GUID);
        FieldDescription taxCodeDescription = FieldDescription.CreateIntegerField("Tax_Code");
        FieldDescription addressDescription = FieldDescription.CreateStringField("Parcel_Address", 150);
    
        List<FieldDescription> fieldsToAdd = new List<FieldDescription>
          {
            globalIdField, parcelIdDescription,
            taxCodeDescription, addressDescription
          };
    
        // Add new fields on the new FieldDescription list
        List<FieldDescription> modifiedFieldDescriptions = new List<FieldDescription>(originalFeatureClassDescription.FieldDescriptions);
        modifiedFieldDescriptions.AddRange(fieldsToAdd);
    
        // The new FeatureClassDescription with additional fields
        FeatureClassDescription modifiedFeatureClassDescription = new FeatureClassDescription(originalFeatureClassDescription.Name,
          modifiedFieldDescriptions, originalFeatureClassDescription.ShapeDescription);
    
        SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
    
        // Update the 'Parcels' FeatureClass with newly added fields
        schemaBuilder.Modify(modifiedFeatureClassDescription);
        bool modifyStatus = schemaBuilder.Build();
    
        if (!modifyStatus)
        {
          IReadOnlyList<string> errors = schemaBuilder.ErrorMessages;
        }
      }
    }
    Create Domain and Field Definition on KG Schemas with SchemaBuilder
    {
        await QueuedTask.Run(() =>
        {
          using (var kg = GetKnowledgeGraph(url))
          {
            var entity_name = "Fruit";
    
            //Domains are managed on the GDB objects...
            var fruit_fc = kg.OpenDataset<FeatureClass>(entity_name);
            var fruit_fc_def = fruit_fc.GetDefinition();
    
            var fieldFruitTypes = fruit_fc_def.GetFields()
                  .FirstOrDefault(f => f.Name == "FruitTypes");
            var fieldShelfLife = fruit_fc_def.GetFields()
                .FirstOrDefault(f => f.Name == "ShelfLife");
    
            //Create a coded value domain and add it to a new field
            var fruit_cvd_desc = new CodedValueDomainDescription(
              "FruitTypes", FieldType.String,
              new SortedList<object, string> {
                          { "A", "Apple" },
                          { "B", "Banana" },
                          { "C", "Coconut" }
              })
            {
              SplitPolicy = SplitPolicy.Duplicate,
              MergePolicy = MergePolicy.DefaultValue
            };
    
            //Create a Range Domain and add the domain to a new field description also
            var shelf_life_rd_desc = new RangeDomainDescription(
                                          "ShelfLife", FieldType.Integer, 0, 14);
    
            var sb = new SchemaBuilder(kg);
            sb.Create(fruit_cvd_desc);
            sb.Create(shelf_life_rd_desc);
    
            //Create the new field descriptions that will be associated with the
            //"new" FruitTypes coded value domain and the ShelfLife range domain
            var fruit_types_fld = new ArcGIS.Core.Data.DDL.FieldDescription(
                                          "FruitTypes", FieldType.String);
            fruit_types_fld.SetDomainDescription(fruit_cvd_desc);
    
            //ShelfLife will use the range domain
            var shelf_life_fld = new ArcGIS.Core.Data.DDL.FieldDescription(
    "ShelfLife", FieldType.Integer);
            shelf_life_fld.SetDomainDescription(shelf_life_rd_desc);
    
            //Add the descriptions to the list of field descriptions for the
            //fruit feature class - Modify schema needs _all_ fields to be included
            //in the schema, not just the new ones to be added.
            var fruit_fc_desc = new FeatureClassDescription(fruit_fc_def);
    
            var modified_fld_descs = new List<ArcGIS.Core.Data.DDL.FieldDescription>(
              fruit_fc_desc.FieldDescriptions);
    
            modified_fld_descs.Add(fruit_types_fld);
            modified_fld_descs.Add(shelf_life_fld);
    
            //Create a feature class description to modify the fruit entity
            //with the new fields and their associated domains
            var updated_fruit_fc =
              new FeatureClassDescription(entity_name, modified_fld_descs,
                                          fruit_fc_desc.ShapeDescription);
    
            //Add the modified fruit fc desc to the schema builder
            sb.Modify(updated_fruit_fc);
    
            //Run the schema builder
            try
            {
              if (!kg.ApplySchemaEdits(sb))
              {
                var err_msg = string.Join(",", sb.ErrorMessages.ToArray());
                System.Diagnostics.Debug.WriteLine($"Create domains error: {err_msg}");
              }
            }
            catch (Exception ex)
            {
              System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
          }
        });
      }
    Modifying domain
    {
      // Must be called within QueuedTask.Run
      void ModifyDomain(Geodatabase geodatabase, string codedValueDomainName = "Pipe")
      {
        SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
        CodedValueDomain codedValueDomain = geodatabase.GetDomains().First(f => f.GetName().Equals(codedValueDomainName)) as CodedValueDomain;
        CodedValueDomainDescription codedValueDomainDescription = new CodedValueDomainDescription(codedValueDomain);
    
        // Update domain description
        codedValueDomainDescription.Description = "Water Pipe Domain";
    
        // Adding code/value pair
        codedValueDomainDescription.CodedValuePairs.Add("C", "Copper");
    
        schemaBuilder.Modify(codedValueDomainDescription);
    
        // To modify the orders of coded value domain
        // schemaBuilder.Modify(codedValueDomainDescription,SortBy.Name,SortOrder.Ascending);
    
        schemaBuilder.Build();
      }
    }
    Removing subtype field designation
    {
      // Must be called within QueuedTask.Run
      void DeleteSubtypeField(SchemaBuilder schemaBuilder, FeatureClassDefinition featureClassDefinition)
      {
        FeatureClassDescription featureClassDescription = new FeatureClassDescription(featureClassDefinition);
    
        // Set subtype field to null to remove the subtype field designation 
        featureClassDescription.SubtypeFieldDescription = null;
    
        schemaBuilder.Modify(featureClassDescription);
        schemaBuilder.Build();
      }
    }
    Modifying subtypes
    {
      // Must be called within QueuedTask.Run
      void ModifySubtypes(SchemaBuilder schemaBuilder, TableDefinition tableDefinition)
      {
        TableDescription tableDescription = new TableDescription(tableDefinition);
    
        // Remove the first subtype from the table
        IReadOnlyList<Subtype> subtypes = tableDefinition.GetSubtypes();
        tableDescription.SubtypeFieldDescription.Subtypes.Remove(subtypes.First().GetCode());
    
        // Adding a new subtype, 'Utility', in the existing table
        tableDescription.SubtypeFieldDescription.Subtypes.Add(4, "Utility");
    
        // Assigning 'Utility' subtype as the default subtype
        tableDescription.SubtypeFieldDescription.DefaultSubtypeCode = 4;
    
        schemaBuilder.Modify(tableDescription);
        schemaBuilder.Build();
      }
    }
    Add relationship rules to a relationship class
    {
      // Must be called within QueuedTask.Run
      void ModifyRelationshipClass(SchemaBuilder schemaBuilder, AttributedRelationshipClassDefinition attributedRelationshipClassDefinition)
      {
        AttributedRelationshipClassDescription attributedRelationshipClassDescription = new AttributedRelationshipClassDescription(attributedRelationshipClassDefinition);
    
        // Update the relationship split policy
        attributedRelationshipClassDescription.RelationshipSplitPolicy = RelationshipSplitPolicy.UseDefault;
    
        // Add field in the intermediate table
        attributedRelationshipClassDescription.FieldDescriptions.Add(FieldDescription.CreateIntegerField("RelationshipStatus"));
    
        // Add relationship rules based on subtypes,if available
        // Assuming origin class has subtype with code 1
        attributedRelationshipClassDescription.RelationshipRuleDescriptions.Add(
          new RelationshipRuleDescription(1, null));
    
        // Enqueue modify operation
        schemaBuilder.Modify(attributedRelationshipClassDescription);
    
        // Execute modify DDL operation
        schemaBuilder.Build();
      }
    }
    Modifying annotation labels and symbols
    {
      // Must be called within QueuedTask.Run
      void ModifyAnnotationLabelAndSymbols(SchemaBuilder schemaBuilder, AnnotationFeatureClassDefinition annotationFeatureClassDefinition)
      {
        AnnotationFeatureClassDescription annotationFeatureClassDescription = new AnnotationFeatureClassDescription(annotationFeatureClassDefinition);
        IReadOnlyList<CIMLabelClass> labelClasses = annotationFeatureClassDescription.LabelClasses;
    
        // Adding a new annotation label class 
        List<CIMLabelClass> modifiedLabelClasses = new List<CIMLabelClass>(labelClasses);
        modifiedLabelClasses.Add(new CIMLabelClass()
        {
          Name = "RedSymbol",
          TextSymbol = new CIMSymbolReference
          {
            Symbol = new CIMTextSymbol()
            {
              Angle = 45,
              FontType = FontType.Type1,
              FontFamilyName = "Arial",
              FontEffects = FontEffects.Normal,
              HaloSize = 2.0,
    
              Symbol = new CIMPolygonSymbol
              {
                SymbolLayers = new CIMSymbolLayer[]
                  { new CIMSolidFill { Color = CIMColor.CreateRGBColor(255, 0, 0) } },
                UseRealWorldSymbolSizes = true
              }
            },
            MaxScale = 0,
            MinScale = 0,
            SymbolName = "TextSymbol-RED"
          }
        });
    
        // Adding a  new symbol
        annotationFeatureClassDescription.Symbols.Add(new CIMSymbolIdentifier()
        {
          ID = 1001,
          Name = "ID_10001",
          Symbol = new CIMTextSymbol()
          {
            Angle = 43,
            FontEffects = FontEffects.Subscript,
            FontType = FontType.TTOpenType,
            FontStyleName = "Regular",
            FontFamilyName = "Tahoma",
            TextCase = TextCase.Allcaps
          }
        });
    
        // Modify annotation feature class 
        AnnotationFeatureClassDescription modifiedAnnotationFeatureClassDescription = new AnnotationFeatureClassDescription(annotationFeatureClassDescription.Name,
            annotationFeatureClassDescription.FieldDescriptions, annotationFeatureClassDescription.ShapeDescription,
            annotationFeatureClassDescription.GeneralPlacementProperties, modifiedLabelClasses);
    
        // Enqueue modify
        schemaBuilder.Modify(modifiedAnnotationFeatureClassDescription);
    
        // DDL execute
        schemaBuilder.Build();
      }
    }
    Modifying an existing field
    {
      // Must be called within QueuedTask.Run
      void ModifyExistingField(SchemaBuilder schemaBuilder, TableDefinition tableDefinition, string fieldNameToBeModified = "PropertyAddress")
      {
        Field field = tableDefinition.GetFields().FirstOrDefault(f => f.Name.Contains(fieldNameToBeModified));
    
        // Update field's alias name and length
        FieldDescription fieldDescription = new FieldDescription(field)
        {
          AliasName = "Physical Property Address",
          Length = 50
        };
    
        // Update the default value
        fieldDescription.SetDefaultValue("123 Main St");
    
        // Enqueue modify operation
        schemaBuilder.Modify(new TableDescription(tableDefinition), field.Name, fieldDescription);
    
        // Execute DDL
        schemaBuilder.Build();
      }
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also