% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/boundary_table.R
\name{set_boundary}
\alias{set_boundary}
\alias{get_boundary}
\title{Store and retrieve boundary geometries}
\usage{
set_boundary(GT, df_list, location = "county", overwrite = FALSE)

get_boundary(GT)
}
\arguments{
\item{GT}{GeoTox object.}

\item{df_list}{Named list of data frames containing boundary geometries as sf
objects.}

\item{location}{Name of element in \code{df_list} that contains location boundary
information (default "county").}

\item{overwrite}{Logical indicating whether to overwrite existing 'boundary'
table.}
}
\value{
For \code{set_boundary()}, the same GeoTox object, invisibly. For
\code{get_boundary()}, a data frame with columns 'id' (boundary name) and 'data'
(sf object).
}
\description{
Boundary information is stored as serialized 'BLOB' objects in the 'boundary'
table.
}
\details{
NOTE: This function requires the \code{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.
}
\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)
}
