Define a set of attributes as a dimension's geoattribute
. The set of attribute
values must uniquely designate the instances of the given geographic layer.
Usage
define_geoattribute(db, dimension, attribute, from_layer, by, from_attribute)
# S3 method for star_database
define_geoattribute(
db,
dimension = NULL,
attribute = NULL,
from_layer = NULL,
by = NULL,
from_attribute = NULL
)
Arguments
- db
A
star_database
object.- dimension
A string, dimension name.
- attribute
A vector, attribute names.
- from_layer
A
sf
object.- by
a vector of correspondence of attributes of the dimension with the
sf
layer structure.- from_attribute
A vector, attribute names.
Details
The definition can be done in two ways: Associates the instances of the attributes with the instances of a geographic layer or defines it from the geometry of previously defined geographic attributes.
Multiple attributes can be specified in the attribute
parameter, the geographical
attribute is the combination of all of them.
If defined from a layer (from_layer
parameter), additionally the attributes
used for the join between the tables (dimension and layer tables) must be
indicated (by
parameter).
If defined from another attribute, it should have the same or finer granularity, to obtain the result by grouping its instances. The considered attribute can be the pair that defines longitude and latitude.
If other geographic information has previously been associated with that attribute, the new information is considered and previous instances for which no new information is provided are also added.
If the geometry provided is polygons, a point layer is also generated.
See also
Other star database geographic attributes:
check_geoattribute_geometry()
,
get_geoattribute_geometries()
,
get_geoattributes()
,
get_layer_geometry()
,
get_point_geometry()
,
summarize_layer()
Examples
db <- mrs_db |>
define_geoattribute(
dimension = "where",
attribute = "state",
from_layer = us_layer_state,
by = "STUSPS"
) |>
define_geoattribute(
dimension = "where",
attribute = "region",
from_attribute = "state"
) |>
define_geoattribute(
dimension = "where",
attribute = "city",
from_attribute = c("long", "lat")
)