
Apply Map Themes from a Portable XML to a QGIS Project
Source:R/rfp_qgs_theme_apply.R
rfp_qgs_theme_apply.RdRead a <rfp-themes> document produced by rfp_qgs_theme_export() and
insert its visibility-preset nodes into a destination .qgs file. Layer
names in the portable document are resolved back to the destination's
layer ids by name match; group nodes are copied verbatim.
Usage
rfp_qgs_theme_apply(
path,
themes_file,
themes = NULL,
on_missing_layer = c("warn", "error", "skip"),
backup = TRUE
)Arguments
- path
Character. Path to the destination
.qgsproject file.- themes_file
Character. Path to the portable
<rfp-themes>XML produced byrfp_qgs_theme_export().- themes
Character vector of theme names to apply from
themes_file. IfNULL(default), all themes in the file are applied.- on_missing_layer
How to handle layers referenced by a theme that don't exist in the destination project. One of
"warn"(default — skip the layer, return a row in the result tibble),"error"(raise), or"skip"(silent skip, still recorded in the tibble).- backup
Logical. Write a
<path>.bakcopy of the destination before modifying. DefaultTRUE.
Value
Invisible tibble with one row per applied theme: theme,
layers_applied (int), layers_missing (int), missing (chr —
comma-joined names of layers not found in the destination).
Details
Errors loudly when the destination has duplicate layer names (the dff
bug class — name-based remap can't be safe), or when a theme being
applied already exists in the destination. Use rfp_qgs_themes() +
QGIS Desktop to remove an existing preset first if you want to replace.
Examples
if (FALSE) { # \dontrun{
# Round-trip a theme from one project to another
rfp_qgs_theme_export("source.qgs", themes = "Floodplain")
rfp_qgs_theme_apply("destination.qgs", "source_themes.xml")
} # }