Skip to contents

For categorized/graduated layers, returns the field, color values, and labels suitable for tmap's tm_scale_categorical().

Usage

gq_tmap_classes(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 field, values (named color vector), labels (named by class key, like values), widths (named line-width vector for line layers; NULL otherwise), dashes (named raw-QGIS-dash vector for classes that are dashed; NULL otherwise), and opacities (named, NA meaning opaque; NULL when no class carries an opacity). The dash value is the raw QGIS encoding (named style like "dash dot", or custom pattern like "0.66;2") — consumers map it to their backend's line type (e.g. tmap lty = "dashed" for non-NA entries).

Examples

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

# Name-based lookup
cls <- gq_tmap_classes(reg, "road")
cls$field
#> [1] "road_type"
cls$values
#>   highway  arterial 
#> "#c0392b" "#e67e22" 
cls$labels
#>    highway   arterial 
#>  "Highway" "Arterial" 
cls$widths
#>  highway arterial 
#>      2.0      1.5 
cls$dashes
#>  highway arterial 
#>       NA "0.66;2" 
cls$opacities
#> NULL

# Object-based (backwards compatible)
cls <- gq_tmap_classes(reg$layers$road)