Skip to contents

Writes the SQL WHERE clause the OGR provider applies, onto a layer already in a project - the repair half of rfp_qgs_vector_add()'s subset =, and the only way to filter a layer without a QGIS Desktop round trip. Until this existed every filtered layer in the fleet was hand-written XML, reproducible by nothing (#318).

Usage

rfp_qgs_subset_set(qgs, layer, subset, backup = TRUE)

Arguments

qgs

Character. Path to the project .qgs.

layer

Character. The layer's display name. A name shared by more than one layer is an error naming the candidates rather than a guess.

subset

Character, or NULL to remove the filter entirely.

backup

Logical. Write <qgs>.bak before mutating. Default TRUE.

Value

Invisibly, the subset that was there before - NA_character_ if the layer had none.

Details

Both datasource surfaces are written. QGIS keeps the string on the <maplayer>'s <datasource> and on the <layer-tree-layer>'s @source, and each keeps its own path - the two routinely differ there, in 48 of 54 layers in bcfishpass_mobile, so this replaces only the subset= option on each rather than copying one string over the other.

The layer is not otherwise touched. Its id, name, style, theme membership and tree position are the surfaces a rebuild would move; nothing here rebuilds a node.

Quote string literals with single quotes. A double-quoted token is an SQL identifier, and one naming no column of the layer is refused - see rfp_qgs_vector_add().

Examples

if (FALSE) { # \dontrun{
rfp_qgs_subset_set(qgs, "bcfishobs FISS fish observations CO",
                   "\"species_code\" IN ('CO')")
rfp_qgs_subset_set(qgs, "bcfishobs FISS fish observations CO", NULL)
} # }