[R-sig-Geo] Modifying a column in a Shapefile

Juliane Struve juliane_struve at yahoo.co.uk
Fri Oct 3 14:02:50 CEST 2008


Dear list members,

I am using a grid called "MergedCentroids" in which I need to modify entries in  column "NEARANGLE and write the result into a column "NEARANG_R". I have tried to convert the Spatial Points Data Frame to a data frame in order to do this. I want to convert the updated grid into a new shapefile at the end. This is my code so far:

MergedCentroids <- readOGR("Centroids_Merge.shp","Centroids_Merge")
write.table(MergedCentroids,file="MergedCentroids.csv",sep=",",row.names=F)
MC=read.csv("MergedCentroids.csv")
MCDF<-as.data.frame(MC) 
MCDF$NEARANG_R=ifelse(MCDF$NEARANGLE<0,MCDF$NEARANGLE+360,MCDF$NEARANG)
MCSPDF = SpatialPointsDataFrame(MCDF[,3:4],data.frame(MCDF[,1:16]))
write.pointShape(coordinates(MCSPDF),data.frame(MCSPDF),paste("NEWMCSPDF"))
 
After executing the last statement I get two error messages:
 
write.pointShape(coordinates(MCSPDF),data.frame(MCSPDF),paste("NEWMCSPDF"))
Error in write.dbf(df, paste(file, ".dbf", sep = ""), factor2char = factor2char,  :
  unable to open file
In addition: Warning message:
use writeSpatialShape:
objects other than Spatial objects defined in the sp package are deprecated
 
Would somebody be able to help ? 
 
Many thanks !
 
Juliane 


 Dr. Juliane Struve
Environmental Scientist
10, Lynwood Crescent
Sunningdale SL5 0BL
01344 620811








More information about the R-sig-Geo mailing list