Learn R Programming

sf (version 0.2-2)

st_write: write simple features object to file or database

Description

write simple features object to file or database

Usage

st_write(obj, dsn, layer, driver = "ESRI Shapefile", ..., dataset_options = NULL, layer_options = NULL, quiet = FALSE, factorsAsCharacter = TRUE)

Arguments

obj
object of class sf or sfc
dsn
data source name (interpretation varies by driver - for some drivers, dsn is a file name, but may also be a folder)
layer
layer name (varies by driver, may be a file name without extension)
driver
character; OGR driver name to be used
...
ignored
dataset_options
character; driver dependent dataset creation options; multiple options supported.
layer_options
character; driver dependent layer creation options; multiple options supported.
quiet
logical; suppress info on name, driver, size and spatial reference
factorsAsCharacter
logical; convert factor objects into character strings (default), else into numbers by as.numeric.

Details

columns (variables) of a class not supported are dropped with a warning.

Examples

Run this code
if (Sys.getenv("USER") %in% c("edzer", "travis")) { # load meuse to postgis
 library(sp)
 example(meuse, ask = FALSE, echo = FALSE)
 st_write(st_as_sf(meuse), "PG:dbname=postgis", "meuse_sf", driver = "PostgreSQL",
   layer_options = c("OVERWRITE=yes", "LAUNDER=true"))
 demo(nc, ask = FALSE)
 st_write(nc, "PG:dbname=postgis", "sids", driver = "PostgreSQL", 
   layer_options = "OVERWRITE=true")
}
nc = st_read(system.file("shape/nc.shp", package="sf"), "nc", crs = 4267)
st_write(nc, ".", "nc")

Run the code above in your browser using DataLab