Apply styles from the gq cartographic registry to layers in a spatial data
source. For GPKG/SQLite, writes to the layer_styles table that QGIS
auto-reads on layer open. For file-based formats (GeoJSON, Shapefile, KML),
writes .qml sidecar files.
Usage
rfp_styles_apply(
path,
registry = NULL,
layers = NULL,
xref_layers = NULL,
style_name = "default",
image = "qgis/qgis:latest"
)Arguments
- path
Character. Path to a spatial data file (GPKG, GeoJSON, Shapefile, KML) or a directory containing spatial files.
- registry
List. A gq registry object (e.g., from
gq::gq_reg_main()). IfNULL(the default), loads the main gq registry.- layers
Character vector. Which layers to style.
NULL(default) styles all layers that have a matching registry entry.- xref_layers
Named character vector. Maps data layer names to registry keys when they don't match directly. Names are layer names in the data, values are registry keys (e.g.,
c("whse_fish.pscis_assessment_svw" = "crossings_pscis_assessment")).- style_name
Character. Name for the saved style. Default
"default".- image
Character. Docker image for headless QGIS. Default
"qgis/qgis:latest".
Details
Runs a PyQGIS script inside the official qgis/qgis Docker container.
Docker must be installed and running. The container is ephemeral (--rm)
and only accesses the specified files via bind mounts.
Examples
if (FALSE) { # \dontrun{
# Style a GPKG using the default gq registry
rfp_styles_apply("~/Projects/gis/elk_river_2026/background_layers.gpkg")
# Style with a custom layer-to-registry mapping
rfp_styles_apply(
"background_layers.gpkg",
xref_layers = c("whse_fish.pscis_assessment_svw" = "crossings_pscis_assessment")
)
# Style all spatial files in a project directory
rfp_styles_apply("~/Projects/gis/elk_river_2026/")
# Style a single GeoJSON (writes roads.qml sidecar)
rfp_styles_apply("exports/roads.geojson")
} # }
