write_sf: Functions to write a spatial table to a database.

View source: R/sql_io.R

write_sfR Documentation

Functions to write a spatial table to a database.

Description

Functions to write a spatial table to a database.

Usage

write_sf(
  dat = NULL,
  schema = NULL,
  tbl = NULL,
  key = NULL,
  comment_str = NULL,
  overwrite = TRUE,
  drv,
  dbname,
  cred_file = NULL,
  ...,
  quiet = FALSE
)

Arguments

dat

a spatial data.frame (from the sf or sp package).

schema

database schema.

tbl

database table.

key

Set a primary key in table?

comment_str

Add a comment to table? Recommended.

overwrite

Should an existing database table be overwritten? TRUE (default).

drv

A database driver.

dbname

The database name.

cred_file

An .R file containing the necessary credentials to connect to a different databases (e.g. PostgreSQL). Can contain variables: user, host, port, password, dbname.

...

Arguments passed on to DBI::dbConnect().

quiet

Quiet function call?

Author(s)

Andreas Scharmueller, andschar@proton.me

Examples


# connection to database required
dat = sf::st_sf(id = 1,
                sf::st_sfc(sf::st_point(1:2))) # better to name it!

write_sf(dat, 
         tbl = 'test',
         cred_file = 'TODO_cred.R',
         overwrite = TRUE)



andschar/andmisc documentation built on Jan. 19, 2025, 10:46 a.m.