Skip to contents

Extracts the categories (IDs, descriptions, and colors) from the first style definition stored in a GeoPackage or PostGIS database. The extracted categories are filtered to include only those present in the raster values.

Usage

get_layer_categories(from, r_clc = NULL)

Arguments

from

A data origin. This can be: - A string representing the path to a GeoPackage file. - A `DBI` database connection object to a PostGIS database, created using [RPostgres::dbConnect()].

r_clc

A `terra` raster object containing the raster values to filter the categories. If NULL, returns all categories.

Value

A data frame containing the filtered categories with the following columns: - `id`: The category ID (integer). - `description`: The description of the category (character). - `color`: The color associated with the category in hexadecimal format (character).

Details

The function retrieves the style definitions from the `layer_styles` table in the provided GeoPackage or PostGIS database. It filters the categories to include only those whose IDs match the unique values present in the raster.

It is useful for associating raster values with their corresponding descriptions and colors, typically for visualization or analysis tasks.

See also

Other style functions: copy_styles()

Examples

gpkg_path <- system.file("extdata", "clc.gpkg", package = "clc")

categories <- get_layer_categories(from = gpkg_path)