set_boundary: Store and retrieve boundary geometries

View source: R/boundary_table.R

set_boundaryR Documentation

Store and retrieve boundary geometries

Description

Boundary information is stored as serialized 'BLOB' objects in the 'boundary' table.

Usage

set_boundary(GT, df_list, location = "county", overwrite = FALSE)

get_boundary(GT)

Arguments

GT

GeoTox object.

df_list

Named list of data frames containing boundary geometries as sf objects.

location

Name of element in df_list that contains location boundary information (default "county").

overwrite

Logical indicating whether to overwrite existing 'boundary' table.

Details

NOTE: This function requires the sf package to be installed.

This function takes a named list of sf objects and stores them in the database. If a location boundary (default "county") is provided, then the non-geometry fields will be added to the 'location' table and replaced with a 'location_id' value so they can be linked to data in the 'sample' table.

Value

For set_boundary(), the same GeoTox object, invisibly. For get_boundary(), a data frame with columns 'id' (boundary name) and 'data' (sf object).

Examples

# Setup sf objects
county <- sf::st_sf(
  FIPS = c(10000, 20000),
  geometry = sf::st_sfc(sf::st_point(1:2), sf::st_point(3:4))
)
state <- sf::st_sf(
  STATE = "XYZ",
  geometry = sf::st_sfc(sf::st_point(5:6))
)
df_list <- list(county = county, state = state)

# Add boundary to GeoTox database
GT <- GeoTox() |> set_boundary(df_list)

# Open a connection to GeoTox database
con <- get_con(GT)

# Look at created tables

dplyr::tbl(con, "boundary") |> dplyr::collect()

dplyr::tbl(con, "location") |> dplyr::collect()

# Retrieve boundary from GeoTox database
boundary <- get_boundary(GT)
boundary
boundary |> tibble::deframe()

# Clean up example
DBI::dbDisconnect(con)
file.remove(GT$db_info$dbdir)

GeoTox documentation built on May 20, 2026, 1:07 a.m.