-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
ArcGIS for Desktop Cookbook
By :
Relationships describe how the spatial/nonspatial objects are linked. In a geodatabase, the relationships are stored in relationship classes. In a relationship class, you can relate only two classes (table/feature class) from a geodatabase. Just as with a feature class, a relationship class can be created at the root level of a geodatabase or within a feature dataset.
In a relationship class, you have to decide the followings properties:
For more information about annotation concepts in the geodatabase context, please refer to Chapter 6, Building Better Maps.
You cannot modify the properties of an existing relationship class. You can delete and define it once again. If you delete one class (table/feature class) that participates in a relationship class, the relationship class will be deleted too.
A table/feature class can be involved in more than one relationship class. Those multiple relationships for a table/feature class work well as long as they are coherently defined and don't generate contradictory behaviors. The last step in creating a relationship class is to define rules in order to refine the cardinality based on the subtypes of the feature classes/tables. All types of cardinality support the relationship rules. A relationship rule is a property of the relationship class.
In this section, you will create two simple relationship classes and one composite relationship class between the LandUse feature class, BuildingsR feature class, and Owners table. Those relationships compose a stacked relationship because they link three classes in an open loop, as shown in the following screenshot:

When you define the cardinality, remember that term one can mean zero. For example, in the schema shown in the preceding screenshot, the Buildings (origin) are related to Owners (destination). The cardinality is many-to-many. The relationship allows the following situations:
Follow these steps to create two simple, many-to-many relationship classes:
...\Data\DesigningGeodatabase\Topo5k.gdb\LandUse.LandUse feature dataset, and select New | Relationship Class. For Name of the relationship class, type LandUseToOwners. For Origin table/feature class, select the plus sign on the left-hand side of the LandUse feature dataset to see the LandUse feature class. Select the LandUse feature class. For Destination table/feature class, select the Owners table. Click on Next.ToOwners. For the second relationship label, type ToLandUse. Select the None (no messages propagated) option, and click on Next. Select the cardinality M-N (many-to-many) and click on Next. Select Yes, I would like to add attributes to this relationship class, and click on Next.OwnerProcent in the first empty row. Select Long Integer from the drop-down list. Select Yes for the Allow NULL values option, in the Field Properties section. As the primary key for the origin table, choose OBJECTID from the drop-down list, and as the foreign key, type LandUseID. As the primary key for the origin table, choose OBJECTID, and for foreign key, type OwnerID.Buildings feature dataset, and select the New | Relationship Class. For Name of the relationship class, type BuildingsRToOwners. Repeat the previous steps, and set the relationship according to the following table:|
Relationship |
Value |
|---|---|
|
Origin table/feature class |
|
|
Destination table/feature class |
|
|
Type of relationship |
|
|
Origin to destination label |
|
|
Destination to origin label |
|
|
Message propagation |
None |
|
Cardinality |
M-N (many to many) |
|
Additional attributes |
NO |
|
Origin Table/Feature Class |
Primary Key: Foreign Key: |
|
Destination Table/Feature Class |
Primary Key: Foreign Key: |
Follow these steps to create a composite one-to-many relationship class between LandUse (as parent objects) and BuildingsR (as child objects):
LandUse feature dataset, and select New | Relationship Class. For Name of the relationship class, type LandUseToBuildings. For Origin table/feature class, select the LandUse feature class. For Destination table/feature class, select the plus sign on the left-hand side of the Buildings feature dataset, and select the BuildingsR feature class.ToBuildingsR. For the second relationship label, type ToLandUse. Select the Forward (origin to destination) option and click on Next. Select the cardinality 1-M (one-to-many), and click on Next.LandUseID.Follow these steps to add rules for the LandUseToBuildings relationship class:
LandUseToBuildings relationship class to open a Relationship Class Properties dialog box. Select the Rules tab to see the subtypes for the LandUse and BuildingsR feature classes. You will define relationship rules, as shown in the following table:|
BuildingsR subtypes |
Cardinality (M)
|
Cardinality (M)
|
|---|---|---|
|
Unknown |
0..10 |
0..* |
|
Dwelling |
0..2 |
0 |
|
Administrative buildings and socialcultural |
0..3 |
0 |
|
Industrial and municipal |
0..10 |
0..2 |
|
Historical sites, monuments, statues |
0..2 |
0..* |
|
Dwelling annex |
0..3 |
0..1 |
Other terrains. For Destination Table/Feature class subtypes, click on the Code checkbox on the left-hand side of the Unknown subtype. Click on Unknown to select the subtype and to enable the Origin Cardinality and Destination Cardinality sections.10. Leave the Min value at 0.Dwelling subtype. Click on Dwelling to select subtype and to enable the Origin Cardinality and Destination Cardinality sections.2. Leave the Min value at 0 according to the previous table. The first rule says that an Other terrains parcel subtype can have a maximum of two dwellings. You should see something similar to the following screenshot:
3. For the Min value, type 0. This rule says that there must be between zero and three administrative buildings in a parcel (Other terrains).Unproductive. Leave unchecked the Unknown subtypes in the Destination Table/Feature class subtypes section to allow an unlimited number of Unknown buildings.Industrial and municipal buildings and one Dwelling annex per Unproductive parcel. Select those subtypes from the Destination Table/Feature class subtypes section, and set the maximum value according to the previous table.Dwelling, Administrative buildings, and Historical sites. Select all those subtypes from the Destination Table/Feature class subtypes section, check the Specify the range of associated destination objects option, and set the maximum values to 0.LandUse subtypes from Origin Table/Feature class subtypes, set the Max and Min values to 0. This will not permit BuildingsR to associate with parcel subtypes, such as Arable, Pasture, Meadow, Vineyard, Fruit orchard, Forest, Hydrography, and Transportation.You can find the final geodatabase schema at ...\Data\DesigningGeodatabase\ MyGeodatabaseResults\Topo5k.gdb.
In the previous exercise, you used OBJECTID as the origin primary key field. But you could define your own primary key. The OBJECTID field guarantees a unique value for each record because it is managed by ArcGIS. You can't modify the OBJECTID values, and this can be inconvenient to maintaining the relationships when you are modifying feature geometry (for example: split, merge) or import features to another feature class.
For more details about the advantages and inconvenience of using the OBJECTID field as the primary key, please refer to Geodata/Data types/Relationships and related objects/Relationship class properties from ArcGIS Help (10.2) online.
There is a performance cost when you are working with relationship classes. The relationship classes will slow down the edit process because they must maintain the referential integrity in the geodatabase. A relationship class will assure that all changes you have made in the origin feature class/table will be reflected in the destination feature class/table according to the type and rules of the relationship.
At step 3, you created a many-to-many, simple relationship class between the BuildingsR feature class and the Owners table. A many-to-many relationship class requires an intermediary table that contains two key fields: origin primary key and destination foreign key. Both fields have a foreign key's role. You can see this table in ArcCatalog if you select the LandUseToOwners relationship class table. Select the Preview tab and the Table preview mode from the bottom of the Preview panel to examine the attribute fields.
Follow these steps to test the relationship behavior:
WorkingRelationships.mxd from ...\Data\DesigningGeodatabase. In Table Of Contents, you have two layers (BuildingsR and LandUse), two intermediate tables (LandUseToOwners and BuildingsRToOwners), and one non-spatial table, Owners.LandUseToBuildings composite relationship. Zoom in to the full extent of a map by selecting Full Extent in the Standard toolbar. Relationships are active and can be validated during an edit session.BuildingsR and LandUse using the Select Features tool.BuildingsR and LandUse. Select Expand All Relationships In Branch to see all selected features (blue bullets), related tables, and table records.LandUse layer. You should see something similar to the following screenshot:
LandUse, and navigate to Selection | Open Table Showing Selected Feature to see the LandUse attribute table in the Show selected records mode. Navigate to Table Options | Related Tables, and choose LandUseToBuildingsR: ToBuildingsR. In the Editor toolbar, navigate to Editor | Validate Features. A message box will appear: The feature LandUse(subtype:Other terrains) has 4 related BuildingsR (subtype:Dwelling) features, thus violating the LandUseToBuildings relationships rule that specifies 0-2. Click on OK to close.LandUseToBuildings composite relationship. With the Select Features tool, select the Other terrains parcel with LandUseID=1262. In the Editor toolbar, select Edit Tool. Drag the parcel away from the previous location. The related buildings should follow the parcel. Select Rotate Tool. Rotate the parcel. The building should rotate, too. Delete the parcel using the Delete key. The buildings are deleted, too. Restore the features using Ctrl + Z.Change the font size
Change margin width
Change background colour