Wrapper on sf::st_write for writing an sf or sp object to disk as an ESRI shapefile

write_shape(in_vect, out_file, overwrite = FALSE, verbose = FALSE,
  encoding = "UTF-8", create_dir = FALSE, ...)

Arguments

in_vect

character object to be written to the shapefile. Must be a valid *sp or sf object

out_file

character output file name

overwrite

logical if TRUE, output file will be overwritten if existing, Default: FALSE

verbose

logical if TRUE, provide messages on processing, Default: TRUE

encoding

character encoding to be used to write the DBF of the shapefile, Default: "UTF-8"

create_dir

logical, if TRUE and the folder of out_file does not exist, then the full folder tree up to out_file is created, Default: FALSE (use with caution !)

...

any other arguments to be passed to sf::st_write

Examples

# build a spatialpoints data frame pts <- cbind(1:5, 1:5) dimnames(pts)[[1]] <- letters[1:5] df <- data.frame(a = 1:5) row.names(df) <- letters[5:1] points <- sp::SpatialPointsDataFrame(pts, df, match.ID = TRUE) # Save it to a shape file out_file = tempfile(pattern = "test", tmpdir = tempdir(), fileext = ".shp") mysp_object = points write_shape(mysp_object, out_file, overwrite = TRUE) # read the saved shape in_data <- read_vect(out_file) in_data
#> Simple feature collection with 5 features and 1 field #> geometry type: POINT #> dimension: XY #> bbox: xmin: 1 ymin: 1 xmax: 5 ymax: 5 #> epsg (SRID): NA #> proj4string: NA #> # A tibble: 5 x 2 #> a geometry #> <int> <POINT> #> 1 5 (1 1) #> 2 4 (2 2) #> 3 3 (3 3) #> 4 2 (4 4) #> 5 1 (5 5)