Skip to contents

One set of map styles for QGIS field projects, report figures and web maps

gq keeps the map styles of New Graph’s QGIS field projects in one registry and hands them to the other tools a map is drawn with: tmap for figures in reports and MapLibre GL for web maps. A crossing classed as a barrier is the same red in the field project, the report and the web map, so the maps behind fish passage and restoration planning read the same wherever they are seen. Change a style in the registry and every map that reads it follows.

Map of the Bittner Creek watershed near Prince George showing streams, lakes, roads, railway and PSCIS fish passage assessments coloured by barrier status, with a legend, scale bar and an inset locating the watershed in British Columbia

PSCIS fish passage assessments in the Bittner Creek watershed, classified by barrier status. The crossings, roads and lakes are drawn straight from the gq registry, and the streams and railway take their colours from it; the code is in the Getting started article.

Installation

pak::pak("NewGraphEnvironment/gq")

gq is under active development and its functions change between releases (see NEWS). Pin a release for reproducible work: pak::pak("NewGraphEnvironment/gq@vX.Y.Z").

Example

Load the registry once, then ask for a layer’s style by name. For tmap, a style comes back as arguments for do.call():

library(gq)
reg <- gq_reg_main()

gq_tmap_style(reg, "lake")
#> $fill
#> [1] "#dcecf4"
#>
#> $fill_alpha
#> [1] 0.7
#>
#> $col
#> [1] "#1f78b4"
#>
#> $lwd
#> [1] 0.2

# tm_shape(lakes) + do.call(tm_polygons, gq_tmap_style(reg, "lake"))

A classified layer carries a colour for each class, and the same registry builds a MapLibre GL expression with gq_mapgl_classes():

gq_tmap_classes(reg, "crossings_pscis_assessment")$values
#>   BARRIER  PASSABLE POTENTIAL   UNKNOWN
#> "#ca3c3c" "#33a02c" "#ff7f00" "#bf2ac4"

For QGIS itself, gq_style_qml() returns the path to the style file QGIS wrote, with nothing lost in translation. A layer defined in your own registry CSV gets a QML from gq_qgis_style(), which gq_gpkg_style_write() stores in a GeoPackage so the layer opens in QGIS already styled.

Learn more

Ecosystem

Package Role
link Build, compare and test fish habitat and access models, every fish habitat definition editable
fresh Splits streams at barriers, classifies habitat by species, traces what’s upstream
wet Typical flow in nearly every stream, tested against gauges; station flow and temperature
flooded Maps floodplains from terrain: the valley floor a river can spread across
drift Maps what changed in land cover, where and when, in a floodplain or any area, from free satellite maps or your own
fly Puts BC’s historic airphotos back on the map from free thumbnails
cd How far any BC watershed’s climate has shifted from your chosen baseline
knowledge Starts from each species’ life history and tunes its fish habitat definitions from where sampling did and did not catch it
floodplains Maps BC’s floodplains and how the land in them changed, one watershed group at a time
crate Canonical schemas for data that changes shape, and provenance receipts for outputs
stac_floodplains_bc Floodplains and land-cover change, a screen for where to look; by watershed group

Data and methods it builds on

Most registry styles are extracted from New Graph’s QGIS field project templates by gq_qgs_extract(), which reads the project’s XML; the rest are curated by hand. The bundled example data comes from the BC Freshwater Atlas (streams, lakes and watersheds), the Digital Road Atlas (roads) and the BC Data Catalogue (railway and PSCIS assessments), and the Neexdzii Kwa set adds modelled habitat and crossings from bcfishpass. Watersheds are delineated with fwapg. The rest of the Bittner Creek set is fetched over the web, and the Neexdzii Kwa set was queried from a database built with fwapg and bcfishpass. Basemap tiles are fetched with maptiles, and each tile layer carries its provider’s credit for the map.

Citation

citation("gq")

License

MIT (see LICENSE).