I have a map data whose format is rds
. Now I want to use this data in another software which asks for shp
format. How to convert rds
format data into shp
format in R?
If it is spatial object saved as a R
-specific binary file of "Serialization Interface for Single Objects" type (see ?readRDS
) probably created at some point by saveRDS()
, read your file with
library(rgdal)
library(sp)
x <- readRDS("path/to/the/rds_file.rds")
and then write it with:
rgdal::writeOGR(x, "path/to/destination", "filename", driver = "ESRI Shapefile")
Be sure not to put ".shp" at the end of your output filename.
Also be sure not to put a /
at the end of the destination folder. Otherwise you might face the error
Creation of output file failed
When the error
Error: inherits(obj, "Spatial") is not TRUE
you might have forgotten the x
as the first argument in the writeOGR
function.