ArcGIS Pro 3.1 API Reference Guide
ArcGIS.Core.Data.DDL Namespace / FieldDescription Class / CreateDomainField Method
The name of the ArcGIS.Core.Data.Field to create.
The DomainDescription of the ArcGIS.Core.Data.Field to create.
Example

In This Topic
    CreateDomainField Method
    In This Topic
    Creates a field description for a ArcGIS.Core.Data.Field with a specified DomainDescription.
    Syntax
    public static FieldDescription CreateDomainField( 
       string name,
       DomainDescription domainDescription
    )
    Public Shared Function CreateDomainField( _
       ByVal name As String, _
       ByVal domainDescription As DomainDescription _
    ) As FieldDescription

    Parameters

    name
    The name of the ArcGIS.Core.Data.Field to create.
    domainDescription
    The DomainDescription of the ArcGIS.Core.Data.Field to create.

    Return Value

    A field description for a ArcGIS.Core.Data.Field with a specified DomainDescription.
    Example
    Creating a Table
    public void CreateTableSnippet(Geodatabase geodatabase, CodedValueDomain inspectionResultsDomain)
    {
      // Create a PoleInspection table with the following fields
      //  GlobalID
      //  ObjectID
      //  InspectionDate (date)
      //  InspectionResults (pre-existing InspectionResults coded value domain)
      //  InspectionNotes (string)
    
      // This static helper routine creates a FieldDescription for a GlobalID field with default values
      FieldDescription globalIDFieldDescription = FieldDescription.CreateGlobalIDField();
    
      // This static helper routine creates a FieldDescription for an ObjectID field with default values
      FieldDescription objectIDFieldDescription = FieldDescription.CreateObjectIDField();
    
      // Create a FieldDescription for the InspectionDate field
      FieldDescription inspectionDateFieldDescription = new FieldDescription("InspectionDate", FieldType.Date)
      {
        AliasName = "Inspection Date"
      };
    
      // This static helper routine creates a FieldDescription for a Domain field (from a pre-existing domain)
      FieldDescription inspectionResultsFieldDescription = FieldDescription.CreateDomainField("InspectionResults", new CodedValueDomainDescription(inspectionResultsDomain));
      inspectionResultsFieldDescription.AliasName = "Inspection Results";
    
      // This static helper routine creates a FieldDescription for a string field
      FieldDescription inspectionNotesFieldDescription = FieldDescription.CreateStringField("InspectionNotes", 512);
      inspectionNotesFieldDescription.AliasName = "Inspection Notes";
    
      // Assemble a list of all of our field descriptions
      List<FieldDescription> fieldDescriptions = new List<FieldDescription>()
        { globalIDFieldDescription, objectIDFieldDescription, inspectionDateFieldDescription, inspectionResultsFieldDescription, inspectionNotesFieldDescription };
    
      // Create a TableDescription object to describe the table to create
      TableDescription tableDescription = new TableDescription("PoleInspection", fieldDescriptions);
    
      // Create a SchemaBuilder object
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
    
      // Add the creation of PoleInspection to our list of DDL tasks
      schemaBuilder.Create(tableDescription);
    
      // Execute the DDL
      bool success = schemaBuilder.Build();
    
      // Inspect error messages
      if (!success)
      {
        IReadOnlyList<string> errorMessages = schemaBuilder.ErrorMessages;
        //etc.
      }
    }
    Adding a Field that uses a domain
    public void AddFieldWithDomainSnippet(Geodatabase geodatabase)
    {
      // Adding a field,'PipeType', which uses the coded value domain to the 'Pipes' FeatureClass
    
      //The FeatureClass to add field
      string featureClassName = "Pipes";
    
      SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
    
      // Create a CodedValueDomain description for water pipes
      CodedValueDomainDescription pipeDomainDescription =
        new CodedValueDomainDescription("WaterPipeTypes", FieldType.String,
        new SortedList<object, string> { { "C_1", "Copper" },
          { "S_2", "Steel" } })
        {
          SplitPolicy = SplitPolicy.Duplicate,
          MergePolicy = MergePolicy.DefaultValue
        };
    
      // Create a coded value domain token
      CodedValueDomainToken codedValueDomainToken = schemaBuilder.Create(pipeDomainDescription);
    
      // Create a new description from domain token
      CodedValueDomainDescription codedValueDomainDescription = new CodedValueDomainDescription(codedValueDomainToken);
    
      // Create a field named as 'PipeType' using a domain description
      FieldDescription domainFieldDescription = new FieldDescription("PipeType", FieldType.String)
      { DomainDescription = codedValueDomainDescription };
    
      //Retrieve existing information for 'Pipes' FeatureClass
      FeatureClassDefinition originalFeatureClassDefinition = geodatabase.GetDefinition<FeatureClassDefinition>(featureClassName);
      FeatureClassDescription originalFeatureClassDescription =
        new FeatureClassDescription(originalFeatureClassDefinition);
    
      // Add domain field on existing fields
      List<FieldDescription> modifiedFieldDescriptions = new List<FieldDescription>(originalFeatureClassDescription.FieldDescriptions) { domainFieldDescription };
    
      // Create a new description with updated fields for 'Pipes' FeatureClass 
      FeatureClassDescription featureClassDescription =
        new FeatureClassDescription(originalFeatureClassDescription.Name, modifiedFieldDescriptions,
                                       originalFeatureClassDescription.ShapeDescription);
    
      // Update the 'Pipes' FeatureClass with domain field
      schemaBuilder.Modify(featureClassDescription);
    
      // Build status
      bool buildStatus = schemaBuilder.Build();
    
      // Build errors
      if (!buildStatus)
      {
        IReadOnlyList<string> errors = schemaBuilder.ErrorMessages;
      }
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also