Learn R Programming

geodimension (version 1.0.2)

relate_levels: Relate levels in a dimension

Description

Definition of a direct relationship between two levels of the dimension: the lower level composes the higher level.

Usage

relate_levels(
  gd,
  lower_level_name = NULL,
  lower_level_attributes = NULL,
  upper_level_name = NULL,
  upper_level_key = NULL,
  by_geography = FALSE
)

# S3 method for geodimension relate_levels( gd, lower_level_name = NULL, lower_level_attributes = NULL, upper_level_name = NULL, upper_level_key = NULL, by_geography = FALSE )

Value

A geodimension.

Arguments

gd

A geodimension object.

lower_level_name

A string, name of the lower level.

lower_level_attributes

A vector of attribute names.

upper_level_name

A string, name of the upper lever.

upper_level_key

A vector of attribute names.

by_geography

A boolean.

Details

The relationship may exist by having attributes with common values or by their geographic attributes. In the latter case, the geometry of the upper level must be of the polygon type.

To use the geometric relationship, it must be explicitly indicated by the Boolean parameter.

If no top-level attributes are indicated, the attributes that make up the key are considered by default, only the corresponding attributes of the lower level have to be indicated.

As a special case, if the top level has only one instance, it is not necessary to specify any attributes to define the relationship.

See Also

Other level association functions: add_level(), complete_relation_by_geography(), geodimension(), get_unrelated_instances()

Examples

Run this code
region <-
  geolevel(name = "region",
           layer = layer_us_region,
           key = c("geoid"))

division <-
  geolevel(name = "division",
           layer = layer_us_division,
           key = c("geoid"))

gd <-
  geodimension(name = "gd_us",
               level = region) |>
  add_level(division)

gd <- gd |>
  relate_levels(lower_level_name = "division",
                upper_level_name = "region",
                by_geography = TRUE)

Run the code above in your browser using DataLab