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, ...)
in_vect |
|
---|---|
out_file |
|
overwrite |
|
verbose |
|
encoding |
|
create_dir |
|
... | any other arguments to be passed to |
# 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)