Vesper
Vesper

Reputation: 87

How to convert rds format data into shp format in R?

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?

Upvotes: 1

Views: 4194

Answers (1)

loki
loki

Reputation: 10340

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.

Upvotes: 4

Related Questions