Skip to contents

A map theme records which layer-tree groups it checks by path, and a layer only draws where every group above it is checked (#216). So anything that changes a group's path - renaming it, moving it, deleting it, a hand edit in QGIS Desktop - strands the reference, the group reads as unchecked, and every layer inside is present, enumerated in the theme, visible="1" and invisible. Nothing errors and every count reads healthy.

Usage

rfp_qgs_theme_unbury(qgs, dry_run = TRUE, prune = TRUE, backup = TRUE)

Arguments

qgs

Character. Path to a .qgs project file.

dry_run

Logical. If TRUE (default), report what would change and write nothing.

prune

Logical. Also drop group references that resolve nowhere. Default TRUE.

backup

Logical. Create a .qgs.bak before modifying. Default TRUE, ignored when dry_run = TRUE.

Value

Invisibly, a list of ticked (a theme/group_path data frame) and pruned (character vector of the paths dropped).

Details

This repairs that, and it is cause-agnostic on purpose: it asks what each theme shows and makes those layers reachable, without being told what broke. It therefore covers a project that was renamed, one whose groups were reorganised, and one that arrived carrying the damage from something else.

Two operations, both reported:

  • tick - check the group holding every visible layer a theme currently buries, and every group above it.

  • prune - drop group references that name no group in the tree. They are inert, since QGIS matches group state by path, so this changes no rendering and leaves the project asserting only things that are true.

Nothing is ever unchecked. Only additions are made, so a layer a theme deliberately conceals cannot be revealed - which is what makes this safe to run over a whole project rather than a named theme.

A preset recording no group state at all is left alone. That is presence-significant: one is inferred on the next write, so ticking groups into it would turn "not recorded" into a full declaration nobody asked for.

Why not re-apply the registry

rfp_qgs_theme_add() rewrites the themes the shipped registry carries, and derives their group state, so it repairs those. It cannot repair a theme the registry has never seen, and real projects are mostly those - measured, sern_fraser_2024 carries 16 presets and restoration_wedzin_kwa 15 against the registry's 8. Re-applying the registry took fraser from 29 buried entries to 23 and left wedzin kwa at 22; this takes both to 0.

Examples

qgs <- file.path(tempdir(), "unbury_example.qgs")
file.copy(
  system.file("templates", "bcfishpass_mobile.qgs", package = "rfp"),
  qgs,
  overwrite = TRUE
)
#> [1] TRUE

# A shipped template is already correct, so there is nothing to do.
res <- rfp_qgs_theme_unbury(qgs)
#>  Nothing to do - every visible theme entry draws.
nrow(res$ticked)
#> [1] 0

unlink(qgs)