Skip to contents

The general constructor. Takes a wide data.frame with one row per atom (the finest region) and one column per geoframe, and returns a Geoscale.

Usage

geoscale_from_leaftable(
  leaftable,
  geoframes,
  key = NULL,
  weights = NULL,
  default_weight = NULL,
  members = NULL,
  geometry = NULL,
  name = "",
  desc = "",
  ...
)

Arguments

leaftable

data.frame with one row per atom, one column per name in geoframes, and optionally numeric weight columns.

geoframes

Ordered character vector of geoframe names, coarsest first. Each must be a column of leaftable.

key

Name of the column holding the unique atom key. Defaults to "region" if present, otherwise the finest geoframe (the last entry of geoframes), which is copied into a region column.

weights

Character vector naming the weight columns. Defaults to all numeric columns that are neither geoframes nor reserved names.

default_weight

The weight used when a caller does not name one. Defaults to the first entry of weights.

members

Optional named list giving the ordered code vocabulary per geoframe. Derived from leaftable when NULL (first-appearance order).

geometry

Optional sfc with one geometry per row of leaftable.

name, desc

Short name and description.

...

Further named entries merged into meta (e.g. crs, source).

Value

A Geoscale.

Details

Blank strings ("") in geoframe columns are normalised to NA, meaning "this atom has no code at this geoframe" — partial coverage is normal in real region tables.

Examples

df <- data.frame(
  country = c("C1", "C1", "C1", "C2"),
  zone    = c("Z1", "Z1", "Z2", "Z3"),
  atom    = c("A1", "A2", "A3", "A4"),
  km2     = c(100, 200, 300, 400)
)
geoscale_from_leaftable(df, geoframes = c("country", "zone", "atom"))
#> Geoscale: <unnamed> 
#> Geoframes (3, coarsest first):
#>   - country (2)
#>     - zone (3)
#>       - atom (4)
#> Atoms: 4
#> Weights: km2 (default: km2)