Skip to content
Prev 5114 / 29559 Next

R: substract two columns in a shapefile (but SAGA+R has an bug error)

Dear Prof. Bivand

Tank for help

I tried this cose

library(rgdal)
canopy_height <- readOGR(".", "theme1")
canopy_height$ZDem.sgrd <- canopy_height$Z - canopy_height$Dem.sgrd
writeOGR(canopy_height, ".", "canopy_height", driver="ESRI Shapefile")


because maptool go out of memory, with rgdal the third column appears empty
(value: 0.0000)
I attached a small file of my data set.

Thanks again for your help and time

Ale



-----Messaggio originale-----
Da: Roger Bivand [mailto:Roger.Bivand at nhh.no] 
Inviato: marted? 24 febbraio 2009 10.51
A: Alessandro
Cc: r-sig-geo at stat.math.ethz.ch
Oggetto: Re: [R-sig-Geo] substract two columns in a shapefile (but SAGA+R
has an bug error)
On Tue, 24 Feb 2009, Alessandro wrote:

            
with
Why not do it the simple way?

Either:

library(maptools)
my_SPDF <- readShapeSpatial("myfile.shp")
my_SPDF$ab <- my_SPDF$a - my_SPDF$b
writeSpatialShape(my_SPDF, "mynewfile")

or:

library(rgdal)
my_SPDF <- readOGR(".", "myfile")
my_SPDF$ab <- my_SPDF$a - my_SPDF$b
writeOGR(my_SPDF, ".", "mynewfile", driver="ESRI Shapefile")

Insert a summary(my_SPDF) to check that a and b are what you think, and 
that ab has been created. It won't work if a and/or b are strings.

Roger