View source: R/boundary_table.R
| set_boundary | R Documentation |
Boundary information is stored as serialized 'BLOB' objects in the 'boundary' table.
set_boundary(GT, df_list, location = "county", overwrite = FALSE)
get_boundary(GT)
GT |
GeoTox object. |
df_list |
Named list of data frames containing boundary geometries as sf objects. |
location |
Name of element in |
overwrite |
Logical indicating whether to overwrite existing 'boundary' table. |
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.
For set_boundary(), the same GeoTox object, invisibly. For
get_boundary(), a data frame with columns 'id' (boundary name) and 'data'
(sf object).
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.