1

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?

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

6 Comments

I successfully read the rds file but when I run the output code, there is the Error: inherits(obj, "Spatial") is not TRUE. Why?
you probably forgot to put the object (in my example x) into the writeOGR function. Also see my edit for the needed libraries.
I have installed two packages and put the x in my codes: '>library(rgdal) > library(sp) > a=readRDS('D:/data/chinamap/chinamap.rds') > rgdal::writeOGR(a, "D:/data/chinamap/", "china", driver = "ESRI Shapefile") ', but the error I said still appears. I am very confused.
if this doesn't work either, could you please add the output of class(a) and typeof(a)?
It doesn't work. The output of 'class(a)' is "data.frame", and the output of 'typeof(a)' is "list". Should I covert 'a' to another format?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.