nc = st_read(system.file("shape/nc.shp", package="sf"))
st_write(nc, "nc.shp")
st_write(nc, "nc.shp", delete_layer = TRUE) # overwrites
data(meuse, package = "sp") # loads data.frame from sp
meuse_sf = st_as_sf(meuse, coords = c("x", "y"), crs = 28992)
st_write(meuse_sf, "meuse.csv", layer_options = "GEOMETRY=AS_XY") # writes X and Y as columns
st_write(meuse_sf, "meuse.csv", layer_options = "GEOMETRY=AS_WKT", delete_dsn=TRUE) # overwrites
## Not run: ------------------------------------
# library(sp)
# example(meuse, ask = FALSE, echo = FALSE)
# st_write(st_as_sf(meuse), "PG:dbname=postgis", "meuse_sf",
# layer_options = c("OVERWRITE=yes", "LAUNDER=true"))
# demo(nc, ask = FALSE)
# st_write(nc, "PG:dbname=postgis", "sids", layer_options = "OVERWRITE=true")
## ---------------------------------------------
## Not run: ------------------------------------
# library(sp)
# data(meuse)
# sf = st_as_sf(meuse, coords = c("x", "y"), crs = 28992)
# library(RPostgreSQL)
# conn = dbConnect(PostgreSQL(), dbname = "postgis")
# st_write_db(conn, sf, "meuse_tbl", drop = FALSE)
## ---------------------------------------------
Run the code above in your browser using DataLab