ArcGIS for Desktop Cookbook
上QQ阅读APP看书,第一时间看更新

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), and BS (State of buildings) attribute fields for the Buildings feature class.
  • Two feature classes will share the same domain. The dHYC domain will be assigned to the HYC (Hydrologic category) attribute field for the Watercourse and WatercourseL feature classes.
  • Six domains will be assigned to a single attribute field based on the subtypes of the LandUse feature class. The dUnkn, dArable, dPasture, dMeadow, dVineyard, and dFruitOrchard domains will assign to the SCAT (SubCategory) attribute field for the LandUse feature class based on the subtypes defined for the CAT (Category) subtype field.

How to do it...

Follow these steps to assign domains to attribute fields of the feature classes:

  1. Start ArcCatalog. In Catalog Tree, go to ...\Data\MyGeodatabase\ Topo5k.gdb\Buildings.
  2. Right-click on the Buildings feature class, and navigate to Properties | Fields. Select the BD attribute field. In Field Properties, the Default Value field is 1 because Default Subtype is Dwelling with code with a value of 1. To see the subtypes, select the Subtypes tab. For every subtype, you will assign three different domains to the following fields: BM, Stories, and BS.
  3. 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:
    How to do it...
  4. The default value 0 for the BM field corresponds to the Unknown description. The default value 1 for the Stories field corresponds to a building with one storey. The default value b for the BS field corresponds to a Good state of building. Click on Apply to save changes.
  5. Select the Dwelling subtype. In the Default Values and Domains section, set the Default Value and Domain columns, as shown in the following screenshot:
    How to do it...
  6. 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 of brick (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.
  7. 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.
  8. In Catalog Tree, select the Hydrography feature dataset. Right-click on the Watercourse feature class, and navigate to Properties | Fields. Select the HType attribute field. In Field Properties, the Default Value field is 1 because the Default Subtype field is River, where Code is 1.
  9. 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:
    How to do it...
  10. Continue to assign values to the Default Values and Domain section for the rest of the subtypes, as shown in the following table:
  11. Click on Apply and on OK to save and close the Feature Class Properties dialog.
  12. In Catalog Tree, select the LandUse feature dataset. Right-click on the LandUse feature class, and navigate to Properties | Subtypes. You have 10 subtypes. For every subtype, you will assign a domain and a default value for the SCAT field, as shown in the following table:
  13. 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.

  1. 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 the LandUse feature class. Click on Add. For Output Feature Class, type LandUseImport.
  2. You will keep only two attribute fields: CAT (long) and SCAT (text). These fields are important because the first is a subtype field and the second field uses the subcategory domains for the Landuse feature class. You will delete all other attribute fields from the source feature class. In the Field Map (optional) section, select Zone (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.
  3. Inspect the newly added domains in the Database Properties dialog for Topo5k.gdb. You now have five new domains: dForest, dHydrography, dTransportation, dOtherTerrains, and dUnproductive. Because you don't want to have a duplicate feature class, delete the LandUseImport feature class in ArcCatalog. The added domains still remain as file geodatabase properties.
  4. 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.