
Using subtypes and domains together
In this recipe, you will use both subtypes and domains to better control, constrain, and partially automate the editing processes of the field values.
Getting ready
In this section, you will assign default values and domains to fields and subtype fields for the following feature classes: Buildings
, Watercourse
, WatercourseL
, and LandUse
.
The exercise tests three cases:
- A simple domain assigned to the
BM
(Material
),Stories
(Number of stories
), andBS
(State of buildings
) attribute fields for theBuildings
feature class. - Two feature classes will share the same domain. The
dHYC
domain will be assigned to theHYC
(Hydrologic category
) attribute field for theWatercourse
andWatercourseL
feature classes. - Six domains will be assigned to a single attribute field based on the subtypes of the
LandUse
feature class. ThedUnkn
,dArable
,dPasture
,dMeadow
,dVineyard
, anddFruitOrchard
domains will assign to theSCAT
(SubCategory
) attribute field for theLandUse
feature class based on the subtypes defined for theCAT
(Category
) subtype field.
How to do it...
Follow these steps to assign domains to attribute fields of the feature classes:
- Start ArcCatalog. In Catalog Tree, go to
...\Data\MyGeodatabase\ Topo5k.gdb\Buildings
. - Right-click on the
Buildings
feature class, and navigate to Properties | Fields. Select theBD
attribute field. In Field Properties, the Default Value field is1
because Default Subtype isDwelling
with code with a value of1
. To see the subtypes, select the Subtypes tab. For every subtype, you will assign three different domains to the following fields:BM
,Stories
, andBS
. - In the Subtypes section, select the Unknown subtype by clicking the small box on the left-hand side of the row with code the value of which is
0
. The rows will become black. In the Default Values and Domains section, set the Default Value and Domain columns, as shown in the following screenshot: - The default value
0
for theBM
field corresponds to theUnknown
description. The default value1
for theStories
field corresponds to a building with one storey. The default valueb
for theBS
field corresponds to aGood
state of building. Click on Apply to save changes. - Select the
Dwelling
subtype. In the Default Values and Domains section, set the Default Value and Domain columns, as shown in the following screenshot: - When you define values in the Default Value field, you must think what the most common value used for the
Dwelling
subtype is. For example, most of the dwellings are made ofbrick
(domain code:2
). During an edit session, when a feature is added, split, or merged, the default value will be assigned to the attribute field value. - Continue to assign the same domains to the next four subtypes. Click on Apply and on OK to save and close the Feature Class Properties dialog.
- In Catalog Tree, select the
Hydrography
feature dataset. Right-click on theWatercourse
feature class, and navigate to Properties | Fields. Select the HType attribute field. In Field Properties, the Default Value field is1
because the Default Subtype field isRiver
, where Code is1
. - For every subtype, you will assign a single domain to the HYC attribute field. In the Subtypes section, select the Unknown subtype, and set the Default Value and Domain columns, as shown in the following screenshot:
- Continue to assign values to the Default Values and Domain section for the rest of the subtypes, as shown in the following table:
- Click on Apply and on OK to save and close the Feature Class Properties dialog.
- In Catalog Tree, select the
LandUse
feature dataset. Right-click on theLandUse
feature class, and navigate to Properties | Subtypes. You have 10 subtypes. For every subtype, you will assign a domain and a default value for theSCAT
field, as shown in the following table: - Click on Apply and on OK to save and close the Feature Class Properties dialog.
How it works...
The domains have been assigned to subtypes in the Subtypes section in the Feature Class Properties dialog. If your feature class doesn't have subtypes, you will assign the domains in the Fields section in the Feature Class Properties dialog box.
At step 8, the Arable
subtype has been assigned the dArable
domain for the SCAT attribute field. A good practice is to have similar names for subtypes and related domains. To be easier to read and make a distinction between the field name, subtype name, and domain name, put a small d
, such as dArable
, in front of the domain name. It is intuitive and easy to combine subtypes with different domains.
At step 3, choosing the right domain was a little tricky because the field is BS and the domain is dState
. Another good practice is to keep your own documentation regarding the data type, code, and description for domains and subtypes. Another aspect is the default value for domains.
At step 7, you defined the default value for BM
(Material
), Brick
value. When you add a Dwelling
feature, the default values of the Material
field will be Brick
. Probably this will help the editing process, but sometimes it can be an illusory value. The user will not be more preoccupied with the correctness of this value. It would be a good idea to define as the default value for the Material
field, code 0
(Unknown
). This value will warn the user that it should be changed to this value according to the reality. There is no perfect solution for a default value, but your experience and the context of using geodatabase will help you to make the most appropriate decision.
There's more...
In the last step, you assigned only six domains to the LandUse
feature class only if it defined 11 subtypes. There is another way to complete the domain list—by importing a feature class from another file geodatabase. When a feature class is imported, all the domains used by the imported feature class will also be added. Follow these steps to import the LandUse
feature class from another file geodatabase, TOPO5000.gdb
.
- In Catalog Tree, right-click on the
LandUse
feature dataset, and navigate to Import | Feature Class (single). For Input Features, go to...\Data\TOPO5000.gdb\LandUse
, and select theLandUse
feature class. Click on Add. For Output Feature Class, typeLandUseImport
. - You will keep only two attribute fields:
CAT
(long) andSCAT
(text). These fields are important because the first is a subtype field and the second field uses the subcategory domains for theLanduse
feature class. You will delete all other attribute fields from the source feature class. In the Field Map (optional) section, selectZone
(long), and select the X button on the right-hand side. Repeat the step for the remaining fields. Click on OK to close the Feature Class to Feature Class dialog. - Inspect the newly added domains in the Database Properties dialog for
Topo5k.gdb
. You now have five new domains:dForest
,dHydrography
,dTransportation
,dOtherTerrains
, anddUnproductive
. Because you don't want to have a duplicate feature class, delete theLandUseImport
feature class in ArcCatalog. The added domains still remain as file geodatabase properties. - Repeat step 12 from the How to do it... section to continue to add domains for the
SCAT
field, as shown in the following table:
You can find the results of this section at ...\Data\DesigningGeodatabase\Topo5k.gdb
.
See also
- In the following Creating a relationship class recipe, you will go a step further in defining the behavior of a file geodatabase. You will create relationships rules between different feature classes.