1

I open a shapefile with the rgdal lib:

foo <- readOGR(dsn="myfolder",layer="myshapefileWithoutEnding")
foo.df <- as(foo, "data.frame")

Then I add a column to the data frame with

foo.df$MY_VALUE <- myDataFrameWithOneColumn

The I check if it looks fine with print(foo.df) and it does, foo.df shows my values as a new column

Then I write the shapefile

writeOGR(foo, ".", myfilename, driver="ESRI Shapefile")  

It saves 4 files, everything looks fine.

But when I open the shapefile in a viewer, I can't see my added column. Everything looks like before.

Any idea why?

2

OMG, I added a whole dataframe to my object. So in the end I have this:

 library(rgdal)  
 foo <- readOGR(dsn="myfolder",layer="myshapefileWithoutEnding")
 foo@data$MY_VALUE <- myDataFrameWithOneColumn[,1]
 writeOGR(foo, ".", myfilename, driver="ESRI Shapefile",overwrite_layer=TRUE) 

Now it works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.