In this topic
- About creating subtypes
- Adding subtypes to a feature class
- Assigning domains and default values to fields at the subtype level
- Resetting subtype codes
About creating subtypes
Although all objects in a feature class or object class must have the same behavior and attributes, not all objects have to share the same default values and validation rules. Features and objects can be grouped into subtypes. Subtypes differentiate objects based on their rules. Use the ISubtypes interface to manage and query subtypes, domains, and default values associated with an object class. The following properties can be set using the ISubtypes interface:
- Default subtype code
- Field containing subtype codes
- Default values for the subtype
- Domain associated with a field subtype pair
To determine whether an object class has subtypes, check the ISubtypes.HasSubtype property.
Adding subtypes to a feature class
Subtypes can only be short or long integers (esriFieldTypeSmallInteger or esriFieldTypeInteger). If a subtype code already exists when the default subtype code is set, it will be deleted. A subtype field must be specified before setting the subtype code value.
In the following code example, a subtype was added to a pipe feature class. The PipeType field (esriFieldTypeSmallInteger) of the pipe feature class will be used for the subtype field. The code example consists of the following subtypes:
- The first subtype with a value of 1 represents the primary pipelines.
- The second subtype with a value of 2 represents the secondary pipelines.
Once the subtypes are created, the DefaultSubtypeCode can be set. In this case, the "Primary" pipe type is chosen to be the default by indicating a subtype code of 1.
[C#] public void AddPipeSubtypes(IFeatureClass featureClass)
{
// Cast the feature class to the ISubtypes interface.
ISubtypes subtypes=(ISubtypes)featureClass;
// Assign "PipeType" as the subtype field.
subtypes.SubtypeFieldName="PipeType";
// Add the subtypes.
subtypes.AddSubtype(1, "Primary");
subtypes.AddSubtype(2, "Secondary");
// Assign the default subtype code.
subtypes.DefaultSubtypeCode=1;
}
[VB.NET] Public Sub AddPipeSubtypes(ByVal featureClass As IFeatureClass)
' Cast the feature class to the ISubtypes interface.
Dim subtypes As ISubtypes=CType(featureClass, ISubtypes)
' Assign "PipeType" as the subtype field.
subtypes.SubtypeFieldName="PipeType"
' Add the subtypes.
subtypes.AddSubtype(1, "Primary")
subtypes.AddSubtype(2, "Secondary")
' Assign the default subtype code.
subtypes.DefaultSubtypeCode=1
End Sub
Assigning domains and default values to fields at the subtype level
In the following code example, the feature class also contains fields for the pipe construction material (Material) and the diameter of the pipe (Diameter). Domains have been created in the workspace to constrain the accurate criteria of these values for each of the different types of pipes (primary or secondary). Apply a domain to a subtype before applying the default value.
Also, in the following code example, different default values for each field based on the subtype will be assigned and the domains will be associated at the subtype level.
[C#] public void SetDefaultsForSubtypes(IWorkspaceDomains workspaceDomains, ISubtypes
subtypes)
{
// The Diameter field in this example is an esriFieldTypeString field while
// the Material field type is esriFieldTypeInteger.
// Set the default value for the Diameter field on the primary subtype to 12.
subtypes.set_DefaultValue(1, "Diameter", "12");
// Set the domain for the Material field on the primary subtype to be the
// PrimaryMaterials domain.
IDomain primaryMaterialsDomain=workspaceDomains.get_DomainByName(
"PrimaryMaterials");
subtypes.set_Domain(1, "Material", primaryMaterialsDomain);
// Assign remaining domains at the subtype level.
IDomain primaryDiametersDomain=workspaceDomains.get_DomainByName(
"PrimaryDiameters");
subtypes.set_Domain(1, "Diameter", primaryDiametersDomain);
IDomain secondaryDiametersDomain=workspaceDomains.get_DomainByName(
"SecondaryDiameters");
subtypes.set_Domain(2, "Diameter", secondaryDiametersDomain);
IDomain secondaryMaterialsDomain=workspaceDomains.get_DomainByName(
"SecondaryMaterials");
subtypes.set_Domain(2, "Material", secondaryMaterialsDomain);
// Assign the remaining default values at the subtype level.
subtypes.set_DefaultValue(1, "Material", 1);
// In this case, 1 represents the domain code for steel.
subtypes.set_DefaultValue(2, "Diameter", "4");
subtypes.set_DefaultValue(2, "Material", 2);
// In this case, 2 represents the domain code for copper.
}
[VB.NET] Public Sub SetDefaultsForSubtypes(ByVal workspaceDomains As IWorkspaceDomains, ByVal subtypes As ISubtypes)
' The Diameter field in this example is an esriFieldTypeString field while
' the Material field type is esriFieldTypeInteger.
' Set the default value for the Diameter field on the primary subtype to 12.
subtypes.DefaultValue(1, "Diameter")="12"
' Set the domain for the Material field on the primary subtype to be the
' PrimaryMaterials domain.
subtypes.Domain(1, "Material")=workspaceDomains.DomainByName("PrimaryMaterials")
' Assign remaining domains at the subtype level.
subtypes.Domain(1, "Diameter")=workspaceDomains.DomainByName("PrimaryDiameters")
subtypes.Domain(2, "Diameter")=workspaceDomains.DomainByName("SecondaryDiameters")
subtypes.Domain(2, "Material")=workspaceDomains.DomainByName("SecondaryMaterials")
' Assign the remaining default values at the subtype level.
subtypes.DefaultValue(1, "Material")=1 ' In this case, 1 represents the domain code for steel.
subtypes.DefaultValue(2, "Diameter")="4"
subtypes.DefaultValue(2, "Material")=2 ' In this case, 2 represents the domain code for copper.
End Sub
Resetting subtypes codes
The following code example shows how to reset the subtypes of an object class. When resetting the subtype codes, all previously created subtypes will be removed. This is done by assigning an empty string to the SubtypeFieldName property. The following code example verifies the feature class passed in has subtypes and resets them if they are present:
[C#] public void ResetSubtypes(IObjectClass objectClass)
{
ISubtypes subtypes=(ISubtypes)objectClass;
if (subtypes.HasSubtype)
{
// The Subtype field can be reset by assigning an empty string to SubtypeFieldName.
subtypes.SubtypeFieldName="";
}
else
{
Console.WriteLine("The class has no subtype defined.");
}
}
[VB.NET] Public Sub ResetSubtypes(ByVal objectClass As IObjectClass)
Dim subtypes As ISubtypes=CType(objectClass, ISubtypes)
If subtypes.HasSubtype Then
' The Subtype field can be reset by assigning an empty string to SubtypeFieldName.
subtypes.SubtypeFieldName=""
Else
Console.WriteLine("The class has no subtype defined.")
End If
End Sub
See Also:
Creating and modifying domainsTo use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
- ESRI.ArcGIS.Geodatabase
- ESRI.ArcGIS.System (ESRI.ArcGIS.esriSystem)
Development licensing | Deployment licensing |
---|---|
ArcGIS Desktop Basic | ArcGIS Desktop Basic |
ArcGIS Desktop Standard | ArcGIS Desktop Standard |
ArcGIS Desktop Advanced | ArcGIS Desktop Advanced |
Engine Developer Kit | Engine: Geodatabase Update |