Skip to contents

Resolves a layer by name and returns a plain list of style properties. No backend-specific objects (tmap, mapgl, etc.) — just colors, widths, shapes, classification fields, and values.

Usage

gq_style(layer_or_reg, name = NULL, field = NULL)

Arguments

layer_or_reg

Either a layer entry from the registry (e.g., reg$layers$lake) or a full registry list when using name-based lookup.

name

Optional layer name for name-based lookup. Accepts name_qgis_snake (e.g., "lake") or name_qgis (e.g., "Crossings - PSCIS assessment"). Normalized to match registry keys.

field

Optional character string to override the classification field name. Useful when data comes from an alternative source with a different column name (e.g., bcfishpass barrier_status vs WHSE barrier_result_code). inst/registry/xref_layers.csv lists the known alternatives: for each layer key, the database table the bundled data was queried from (name_table, e.g. bcfishpass.crossings) and the column that table classifies on (class_field).

Value

A named list with type and style properties. For simple layers: fill, stroke, mark as applicable. For classified layers: adds classification with field, values (named color vector), labels, and per-class widths/radii/dashes/opacities when available. labels and every per-class vector are named by class key, as values is, so cls$labels[codes] and cls$values[codes] index the same classes. dashes holds the raw QGIS dash value (named style like "dash dot", or custom pattern like "0.66;2") for classes that are dashed. opacities is NA for a class the registry gives no opacity, which means opaque: the extractor records opacity only when it is below 1. casing_colors and casing_widths are present when any class is cased (a wider line drawn beneath it), NA for a class that is not; outline_colors, outline_widths and outline_opacities likewise for a polygon class's outline. A simple layer passes casing and overlay through as the registry holds them, and any layer its label. No translator draws casing or overlay yet: draw each as its own layer, the casing beneath its core, and beneath every core where the layer's casings should not cross (QGIS's symbol levels, as on roads_dra).

Examples

path <- system.file("examples", "mini_registry.json", package = "gq")
reg <- gq_registry_read(path)

# Simple polygon
gq_style(reg, "lake")
#> $type
#> [1] "polygon"
#> 
#> $fill
#> $fill$color
#> [1] "#c6ddf0"
#> 
#> $fill$opacity
#> [1] 0.85
#> 
#> 
#> $stroke
#> $stroke$color
#> [1] "#7ba7cc"
#> 
#> $stroke$width
#> [1] 0.5
#> 
#> 

# Simple line
gq_style(reg, "stream")
#> $type
#> [1] "line"
#> 
#> $stroke
#> $stroke$color
#> [1] "#7ba7cc"
#> 
#> $stroke$width
#> [1] 0.4
#> 
#> $stroke$opacity
#> [1] 0.8
#> 
#> 

# Classified line — includes field, values, labels
gq_style(reg, "road")
#> $type
#> [1] "line"
#> 
#> $classification
#> $classification$field
#> [1] "road_type"
#> 
#> $classification$values
#>   highway  arterial 
#> "#c0392b" "#e67e22" 
#> 
#> $classification$labels
#>    highway   arterial 
#>  "Highway" "Arterial" 
#> 
#> $classification$widths
#>  highway arterial 
#>      2.0      1.5 
#> 
#> $classification$dashes
#>  highway arterial 
#>       NA "0.66;2" 
#> 
#> 

# Override classification field for alternative data source
gq_style(reg, "road", field = "my_road_type")
#> $type
#> [1] "line"
#> 
#> $classification
#> $classification$field
#> [1] "my_road_type"
#> 
#> $classification$values
#>   highway  arterial 
#> "#c0392b" "#e67e22" 
#> 
#> $classification$labels
#>    highway   arterial 
#>  "Highway" "Arterial" 
#> 
#> $classification$widths
#>  highway arterial 
#>      2.0      1.5 
#> 
#> $classification$dashes
#>  highway arterial 
#>       NA "0.66;2" 
#> 
#> 

# Object-based (backwards compatible)
gq_style(reg$layers$lake)
#> $type
#> [1] "polygon"
#> 
#> $fill
#> $fill$color
#> [1] "#c6ddf0"
#> 
#> $fill$opacity
#> [1] 0.85
#> 
#> 
#> $stroke
#> $stroke$color
#> [1] "#7ba7cc"
#> 
#> $stroke$width
#> [1] 0.5
#> 
#>