Skip to contents

A map theme (QGIS calls the stored form a visibility preset) records which layers are visible, and which layer-tree groups are checked and expanded. This returns both, in the shape rfp_qgs_theme_set() accepts - so reading from one project and setting into another is how a theme is ported, with no intermediate file.

Usage

rfp_qgs_themes(path)

Arguments

path

Character. Path to a .qgs project file.

Value

A list of four data frames:

  • layers - theme, layer, visible, expanded, style

  • groups - theme, group_path, state ("checked" / "expanded")

  • themes - one row per theme: expanded_info, group_attr, group_info, single_root. Carries what the writer needs to reproduce a theme faithfully, in particular whether QGIS should APPLY its group and expansion state or ignore it. Pass the whole list to rfp_qgs_theme_set() - a theme missing from here is written as a new one, with its group state inferred from where its layers sit.

  • legend - theme, layer, node, state: per-class legend visibility and expansion, i.e. which categories or rules of a layer the theme turns on. node ids are opaque (integers for categorized renderers, {uuid} for rule-based). A checked row with node = NA records a block that is present but empty - meaning no class is checked, which is not the same as the layer having no block at all.

A theme with no layers still appears in groups, and in rfp_qgs_theme_names(), so it can still be removed or kept by name.

Details

Layers are identified by name, not by the project-local id they are stored under, because a name is the only thing meaningful in another project. Groups are identified by their /-joined tree path.

Examples

path <- system.file("testdata", "test_themes.qgs", package = "rfp")
themes <- rfp_qgs_themes(path)
themes$layers
#>       theme   layer visible expanded   style
#> 1 Theme One Layer A    TRUE     TRUE default
#> 2 Theme One Layer B    TRUE    FALSE default
#> 3 Theme Two Layer A   FALSE     TRUE default
#> 4 Theme Two Layer C    TRUE     TRUE default
themes$groups
#>       theme  group_path    state
#> 1 Theme One        root  checked
#> 2 Theme One root/group1  checked
#> 3 Theme One root/group1 expanded