After defining a query and geographic dimensions, run the query and select the geographic data associated with it to get a geographic data layer as the result.
Usage
run_geoquery(
dq,
unify_by_grain = TRUE,
fact = NULL,
dimension = NULL,
attribute = NULL,
wider = FALSE
)
# S3 method for class 'dimensional_query'
run_geoquery(
dq,
unify_by_grain = TRUE,
fact = NULL,
dimension = NULL,
attribute = NULL,
wider = FALSE
)
Details
In the case of having several fact tables, as an option, we can indicate if we do not want to unify the facts in the case of having the same grain.
If the result only has one fact table, it is not necessary to provide its name. Nor is it necessary to indicate the name of the geographic dimension if there is only one available.
If no attribute is specified, the geographic attribute of the result with finer granularity is selected.
In geographic layers, geographic objects are not repeated. The tables are
wide: for each object the rest of the attributes are defined as columns. By
means of the parameter wider
we can indicate that we want a result of this
type.
See also
Other geo functions:
define_geoattribute()
,
geomultistar()
,
get_empty_geoinstances()
Examples
gms <- geomultistar(ms = ms_mrs, geodimension = "where") |>
define_geoattribute(
attribute = "city",
from_layer = usa_cities,
by = c("city" = "city", "state" = "state")
) |>
define_geoattribute(
attribute = "state",
from_layer = usa_states,
by = c("state" = "state")
) |>
define_geoattribute(attribute = "region",
from_attribute = "state") |>
define_geoattribute(attribute = "all_where",
from_layer = usa_nation)
gdq <- dimensional_query(gms) |>
select_dimension(name = "where",
attributes = c("state", "city")) |>
select_dimension(name = "when",
attributes = c("when_happened_year", "when_happened_week")) |>
select_fact(
name = "mrs_age",
measures = c("n_deaths")
) |>
select_fact(name = "mrs_cause",
measures = c("pneumonia_and_influenza_deaths", "other_deaths")) |>
filter_dimension(name = "when", when_happened_week <= "03") |>
filter_dimension(name = "where", state == "MA")
sf <- gdq |>
run_geoquery()
sfw <- gdq |>
run_geoquery(wider = TRUE)