ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Data.DDL Namespace / SchemaBuilder Class / Create Method / Create(RangeDomainDescription) Method
Indicates the ArcGIS.Core.Data.RangeDomain to be created.
Example

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

    Parameters

    rangeDomainDescription
    Indicates the ArcGIS.Core.Data.RangeDomain to be created.

    Return Value

    Exceptions
    ExceptionDescription
    For Enterprise geodatabases, ArcGIS.Core.Data.FieldType.Single is invalid for domains. Consider using ArcGIS.Core.Data.FieldType.Double instead.
    rangeDomainDescription is null.
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Example
    Creating a Range domain
    {
      // Must be called within QueuedTask.Run
      void CreateRangeDomainSnippet(Geodatabase geodatabase)
      {
        // Create a range description with minimum value = 0 and maximum value = 1000
        RangeDomainDescription rangeDomainDescriptionMinMax = new RangeDomainDescription("RangeDomain_0_1000",
            FieldType.Integer, 0, 1000)
        { Description = "Domain value ranges from 0 to 1000" };
    
        SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
    
        // Create  a range domain 
        schemaBuilder.Create(rangeDomainDescriptionMinMax);
        schemaBuilder.Build();
      }
    }
    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());
            }
          }
        });
      }
    Creating a table with index from scratch
    {
      // Must be called within QueuedTask.Run
      void CreatingTableWithIndex(SchemaBuilder schemaBuilder)
      {
        FieldDescription nameFieldDescription = FieldDescription.CreateStringField("Name", 50);
        FieldDescription addressFieldDescription = FieldDescription.CreateStringField("Address", 200);
    
        // Creating a feature class, 'Buildings' with two fields
        TableDescription tableDescription = new TableDescription("Buildings",
          new List<FieldDescription>() { nameFieldDescription, addressFieldDescription });
    
        // Enqueue DDL operation to create a table
        TableToken tableToken = schemaBuilder.Create(tableDescription);
    
        // Creating an attribute index named as 'Idx'
        AttributeIndexDescription attributeIndexDescription = new AttributeIndexDescription("Idx", new TableDescription(tableToken),
          new List<string> { nameFieldDescription.Name, addressFieldDescription.Name });
    
        // Enqueue DDL operation to create an attribute index
        schemaBuilder.Create(attributeIndexDescription);
    
        // Execute build indexes operation
        bool isBuildSuccess = schemaBuilder.Build();
      }
    }
    Adding indexes in pre-existing dataset
    {
      // Must be called within QueuedTask.Run
      void AddingIndexes(SchemaBuilder schemaBuilder, FeatureClassDefinition featureClassDefinition)
      {
        // Field names to add in the attribute index
        string fieldName = featureClassDefinition.GetFields().First(f => f.AliasName.Contains("Name")).Name;
        string fieldAddress = featureClassDefinition.GetFields().First(f => f.AliasName.Contains("Address")).Name;
    
        // Creating an attribute index with index name 'Idx' and two participating fields' name
        AttributeIndexDescription attributeIndexDescription = new AttributeIndexDescription("Idx",
          new TableDescription(featureClassDefinition), new List<string> { fieldName, fieldAddress });
    
        // Enqueue DDL operation for an attribute index creation 
        schemaBuilder.Create(attributeIndexDescription);
    
        // Creating the spatial index 
        SpatialIndexDescription spatialIndexDescription = new SpatialIndexDescription(new FeatureClassDescription(featureClassDefinition));
    
        // Enqueue DDL operation for the spatial index creation
        schemaBuilder.Create(spatialIndexDescription);
    
        // Execute build indexes operation
        bool isBuildSuccess = schemaBuilder.Build();
    
        if (!isBuildSuccess)
        {
          IReadOnlyList<string> errors = schemaBuilder.ErrorMessages;
          // Iterate and handle errors 
        }
      }
    }
    Creating table with subtypes
    {
      // Must be called within QueuedTask.Run
      void CreateTableWithSubtypes(SchemaBuilder schemaBuilder)
      {
        // Creating a 'Building' table with the subtype field 'BuildingType'
        FieldDescription buildingType = new FieldDescription("BuildingType", FieldType.Integer);
        FieldDescription buildingName = new FieldDescription("Name", FieldType.String);
    
        TableDescription tableDescription = new TableDescription("Building", new List<FieldDescription> { buildingName, buildingType });
    
        // Add the building type subtype with three subtypes - Business, Marketing, Security
        tableDescription.SubtypeFieldDescription = new SubtypeFieldDescription(buildingType.Name,
          new Dictionary<int, string> { { 1, "Business" }, { 2, "Marketing" }, { 3, "Security" } })
        {
          DefaultSubtypeCode = 3 // Assigning 'Security' building type as the default subtype
        };
    
        schemaBuilder.Create(tableDescription);
        schemaBuilder.Build();
      }
    }
    Creating relationship class
    {
      // Must be called within QueuedTask.Run
      void CreateRelationshipWithRelationshipRules(SchemaBuilder schemaBuilder)
      {
        // Creating a 'BuildingType' table with two fields - BuildingType and BuildingTypeDescription
        FieldDescription buildingType = FieldDescription.CreateIntegerField("BuildingType");
        FieldDescription buildingTypeeDescription = FieldDescription.CreateStringField("BuildingTypeDescription", 100);
        TableDescription buildingTypeDescription = new TableDescription("BuildingType",
          new List<FieldDescription>() { buildingType, buildingTypeeDescription });
        TableToken buildingtypeToken = schemaBuilder.Create(buildingTypeDescription);
    
        // Creating a 'Building' feature class with three fields - BuildingId, Address, and BuildingType
        FieldDescription buildingId = FieldDescription.CreateIntegerField("BuildingId");
        FieldDescription buildingAddress = FieldDescription.CreateStringField("Address", 100);
        FieldDescription usageSubType = FieldDescription.CreateIntegerField("UsageSubtype");
        FeatureClassDescription featureClassDescription = new FeatureClassDescription("Building",
          new List<FieldDescription> { buildingId, buildingAddress, buildingType, usageSubType },
          new ShapeDescription(GeometryType.Polygon, SpatialReferences.WGS84));
    
        // Set subtype details (optional)
        featureClassDescription.SubtypeFieldDescription = new SubtypeFieldDescription(usageSubType.Name,
          new Dictionary<int, string> { { 1, "Marketing" }, { 2, "Utility" } });
    
        FeatureClassToken buildingToken = schemaBuilder.Create(featureClassDescription);
    
        // Creating a 1:M relationship between the 'Building' feature class and 'BuildingType' table
        RelationshipClassDescription relationshipClassDescription = new RelationshipClassDescription(
          "BuildingToBuildingType", new FeatureClassDescription(buildingToken), new TableDescription(buildingtypeToken),
          RelationshipCardinality.OneToMany, buildingType.Name, buildingType.Name)
        {
          RelationshipType = RelationshipType.Composite
        };
    
        // Adding relationship rules for the 'Marketing' subtype
        relationshipClassDescription.RelationshipRuleDescriptions.Add(new RelationshipRuleDescription(1, null));
    
        schemaBuilder.Create(relationshipClassDescription);
        schemaBuilder.Build();
      }
    }
    Creating attributed relationship class
    {
      // Must be called within QueuedTask.Run
      void CreateAttributedRelationship(SchemaBuilder schemaBuilder)
      {
        // Creating a 'BuildingType' table with two fields - BuildingType and BuildingTypeDescription
        FieldDescription buildingType = FieldDescription.CreateIntegerField("BuildingType");
        FieldDescription buildingTypeeDescription = FieldDescription.CreateStringField("BuildingTypeDescription", 100);
        TableDescription buildingTypeDescription = new TableDescription("BuildingType",
          new List<FieldDescription>() { buildingType, buildingTypeeDescription });
        TableToken buildingtypeToken = schemaBuilder.Create(buildingTypeDescription);
    
        // Creating a 'Building' feature class with three fields - BuildingId, Address, and BuildingType
        FieldDescription buildingId = FieldDescription.CreateIntegerField("BuildingId");
        FieldDescription buildingAddress = FieldDescription.CreateStringField("Address", 100);
        FeatureClassDescription featureClassDescription = new FeatureClassDescription("Building",
          new List<FieldDescription> { buildingId, buildingAddress, buildingType },
          new ShapeDescription(GeometryType.Polygon, SpatialReferences.WGS84));
        FeatureClassToken buildingToken = schemaBuilder.Create(featureClassDescription);
    
        // Creating M:M relationship between the 'Building' feature class and 'BuildingType' table
        AttributedRelationshipClassDescription attributedRelationshipClassDescription =
          new AttributedRelationshipClassDescription("BuildingToBuildingType",
            new FeatureClassDescription(buildingToken),
            new TableDescription(buildingtypeToken), RelationshipCardinality.ManyToMany, "OBJECTID", "BuildingID",
            "OBJECTID", "BuildingTypeID");
    
        // Adding optional attribute field in the intermediate table - 'OwnershipPercentage' field
        attributedRelationshipClassDescription.FieldDescriptions.Add(FieldDescription.CreateIntegerField("OwnershipPercentage"));
    
        schemaBuilder.Create(attributedRelationshipClassDescription);
        schemaBuilder.Build();
      }
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also