Drops a layer's <maplayer> and every reference to it - the layer tree, each
map theme that lists it, the ordering lists - then prunes any group the
removal left empty.
Arguments
- qgs
Character. Path to the project
.qgs.- layer
Character vector of layer display names, as they appear in the layer tree. An unknown name is an error listing what the project has - removing five of six and reporting success is the failure worth preventing. A name shared by more than one layer is an error naming the candidates rather than a guess.
- backup
Logical. Write
<qgs>.bakbefore mutating. DefaultTRUE.
Details
Two cases need this, and the second is the one that is easy to argue away:
A dead reference.
rfp_project_create()drops a layer that is empty in the project's AOI, and nothing repairs the project afterwards, so a.qgscan point at a GeoPackage that was never written. QGIS then raises Handle Unavailable Layers on every open - on a phone, the first thing a field user meets.rfp_project_audit()'sdeadelement finds these.A live layer, when the data model changes underneath it. Collapsing six healthy per-watershed layers into two means deleting six working layers, which by hand is four elements each and a theme count that is easy to under-count.
No file is deleted. Only the reference goes, so the operation is reversible by re-adding, and it is safe to run on a live project. Removing a form's data as well is NewGraphEnvironment/rfp#129.
See also
Other qgs:
rfp_qgs_form_add(),
rfp_qgs_preview_set(),
rfp_qgs_raster_add(),
rfp_qgs_service_add(),
rfp_qgs_service_rm(),
rfp_qgs_services(),
rfp_qgs_style_export(),
rfp_qgs_style_set(),
rfp_qgs_subset_get(),
rfp_qgs_subset_set(),
rfp_qgs_theme_add(),
rfp_qgs_theme_lookup(),
rfp_qgs_theme_names(),
rfp_qgs_theme_rm(),
rfp_qgs_theme_set(),
rfp_qgs_theme_unbury(),
rfp_qgs_themes(),
rfp_qgs_vector_add(),
rfp_qwc_config_create(),
rfp_raster_style_path(),
rfp_raster_styles()
Examples
project <- file.path(tempdir(), "layer_rm_example")
dir.create(project)
file.copy(
list.files(
system.file("testdata", "subset_fixture", "parent", package = "rfp"),
full.names = TRUE),
project
)
#> [1] TRUE TRUE TRUE
qgs <- file.path(project, "parent.qgs")
rfp_qgs_layer_rm(qgs, "streams", backup = FALSE)
#> ✔ Removed 1 layer: "streams"
#> ℹ Removed from 1 map theme: "ThemeA (1)". A preset survives under its own name with the entry swept out, so nothing else reports this.
# An unknown name is an error rather than a silent skip.
try(rfp_qgs_layer_rm(qgs, "not a layer", backup = FALSE))
#> Error : No layer named 'not a layer' in this project.
#> Present: lakes, roads, dtm, external, Annotations
unlink(project, recursive = TRUE)
