[R-sig-Geo] R: substract two columns in a shapefile (but SAGA+R has an bug error)

Alessandro alessandro.montaghi at unifi.it
Tue Feb 24 12:39:27 CET 2009


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:

> Dear Researcher,
>
>
>
> I have a shapefile with two columns "a" and "b" and I wish to subtract a-b
> to obtain a new column of difference.  I tried in SAGA + R with the module
> "Table calculator for shapes". This worked without an error, but it didn't
> save the results either. I suspect that this is a bug in the SAGA module.
>
>
>
> Is there an another code or packages (without GRASS+R) to do operation
with
> shapefile?


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

>
>
>
> Thanks
>
>
>
> Ale
>
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no

-------------- next part --------------
A non-text attachment was scrubbed...
Name: theme1.shp
Type: application/octet-stream
Size: 352 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20090224/59bb3e1f/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: theme1.shx
Type: application/octet-stream
Size: 172 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20090224/59bb3e1f/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: theme1.dbf
Type: application/octet-stream
Size: 395 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20090224/59bb3e1f/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: theme1.sbn
Type: application/octet-stream
Size: 220 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20090224/59bb3e1f/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: theme1.sbx
Type: application/octet-stream
Size: 124 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20090224/59bb3e1f/attachment-0004.obj>


More information about the R-sig-Geo mailing list