Skip to contents

Reads a hand-curated CSV file and converts it to the same list structure as gq_registry_read(). Multiple rows per layer_key with a class_field and class_value produce a classification layer. Single rows produce simple fill/stroke/mark/label styles.

Usage

gq_reg_custom(path)

Arguments

path

Path to a CSV file. Only layer_key and type are required. Every other column is optional, and one that is absent is read as empty for every row: source_layer, class_field, class_value, class_label, fill_color, fill_opacity, stroke_color, stroke_width, stroke_opacity, dash, mark_color, mark_shape, mark_radius, mark_stroke_color, mark_stroke_width, label_color, label_size, label_font, label_halo_color, label_halo_width, label_offset_x, label_offset_y, note. Label sizes are in QGIS's units, as the extractor writes them: label_size in points, label_halo_width in millimetres (#103). The offsets are in ems, read as MapLibre's text-offset reads them, positive y downward. dash takes a QGIS line style name as the extractor writes it (solid, no, dash, dot, dash dot, dash dot dot) or a dash pattern of two or more lengths separated by ; or a space ("4;2", "0.66;2"); anything else is an error.

Value

A list with name, version, source, and layers elements, compatible with gq_tmap_style(), gq_mapgl_style(), etc.

Raster layers

A type of "raster" carries a QGIS paletted renderer: one row per palette entry, class_value holding the band value and class_label the palette label. habitat_lateral is the shipped example.

class_field is a sentinel for a raster, not a column name. The classification branch here requires a non-NA class_field, and a paletted raster keys on pixel value rather than on any attribute — so the convention is the literal string "value", meaning band 1. A consumer with a real band name passes it through gq_style(field = ).

Give class_value at least one non-numeric value across the file, or accept that read.csv() will type the column as integer; the reader coerces back to character, but a numeric column reads as an ordinal in every other tool.

What a raster row cannot carry: QGIS's per-value rasterTransparency (habitat_lateral sets 30% on top of the renderer's 0.4 opacity), multi-band renderers, and resampling. Those live in the QML, which is lossless — reach for gq_style_qml() whenever the consumer is QGIS itself.

The tmap and mapgl translators do not render rasters. gq_tmap_style(), gq_mapgl_style() and gq_mapgl_classes() all refuse a raster rather than returning something plausible; gq_tmap_classes() works, since a palette is a classification like any other.

Classified lines

A classified line reads its per-class style from the stroke columns, as an extracted one does: color from stroke_color (or fill_color when that is empty), width from stroke_width, opacity from stroke_opacity (or fill_opacity), and dash from dash. Polygon and raster classes read fill_color and fill_opacity, with the stroke columns as a per-class outline.

Examples

path <- system.file("registry", "reg_custom.csv", package = "gq")
reg <- gq_reg_custom(path)
names(reg$layers)
#>  [1] "bec_zone"                    "rivers_poly"                
#>  [3] "dam"                         "town"                       
#>  [5] "harvest_area"                "planting_site"              
#>  [7] "old_growth_management_areas" "national_park"              
#>  [9] "habitat_lateral"             "habitat_rule_comparison"    
#> [11] "habitat_expected_use"        "floodplain_flood_factor"    
#> [13] "tree_cover_change"           "landcover_change_from"      
#> [15] "landcover_change_to"        

# Classified layer (multiple rows per layer_key)
reg$layers$bec_zone$classification$field
#> [1] "ZONE"
names(reg$layers$bec_zone$classification$classes)
#>  [1] "SBS"  "ESSF" "ICH"  "BWBS" "CWH"  "MS"   "SBPS" "SWB"  "AT"   "MH"  
#> [11] "BG"  

# Simple layer (single row)
reg$layers$rivers_poly$fill
#> $color
#> [1] "#7ba7cc"
#> 
#> $opacity
#> [1] 0.7
#>