[R-sig-Geo] difficult to subtract two column of my shapefile
Robert Hijmans
r.hijmans at gmail.com
Tue Feb 24 16:54:54 CET 2009
indeed, on the example file, this works fine.
library(foreign)
data <- read.dbf('theme1.dbf')
data$AminB <- data$A - data$B
file.remove('theme1.dbf')
write.dbf(data, 'theme1.dbf')
if the dbf is too large you could you use a database to import the
dbf, add the column, export again. Perhaps sqlite (in R).
(((((( in your first post you said you have ArcMap: open attribute
table, options/add field, highlight field, right click/ field
calculator, a - b ))))))
On Tue, Feb 24, 2009 at 10:37 PM, Alexander Brenning
<brenning at uwaterloo.ca> wrote:
> Hi there,
>
> to throw in two more alternatives, there are functions read.dbf and
> write.dbf in packages shapefiles and foreign (see help files for examples;
> the functions differ between the two packages despite having the same name).
>
> Remember that operations on the shapefile attributes only affect the dbf
> file of the shape"file" (which is not really a file but a set of files). So
> this will work as long as you don't change the number or order of the rows.
>
> This may also be more efficient if the shapes have complex geometry (e.g.
> complex polygons, contour lines...), because the geometry is not imported by
> the functions I mentioned.
>
> Cheers
> Alex
>
>
> Alessandro wrote:
>>
>> Thanks for all help
>>
>>
>> I wish two subtract two column of my shapefile but It look like a
>> impossible
>> operation with R:
>>
>>
>> 1. In SAGA+R module: "Table calculator for shapes", It runs but doesn't
>> save the result (there is bug)
>>
>> 2. I can't use software "GeoDa" because It works only in Windows xp and
>> not in Windows Vista
>>
>> 3. Library maptools go down for a memory problems
>>
>> 4. library(rgdal) give an empty column
>>
>>
>> is there suggestion? please.
>>
>>
>> I attach a small part of my data-set for
>>
>> Thanks for Help and suggestion
>>
>>
>>
>> library(maptools)
>>
>> my_SPDF <- readShapeSpatial("theme1.shp")
>> my_SPDF$ab <- my_SPDF$a - my_SPDF$b
>> writeSpatialShape(my_SPDF, "mynewfile")
>>
>>
>> or:
>>
>>
>> library(rgdal)
>>
>> my_SPDF <- readOGR(".", "theme1")
>>
>> my_SPDF$ab <- my_SPDF$a - my_SPDF$b
>>
>> writeOGR(my_SPDF, ".", "mynewfile", driver="ESRI Shapefile")
>>
>>
>>
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
> --
> Alexander Brenning
> brenning at uwaterloo.ca - T +1-519-888-4567 ext 35783
> Department of Geography and Environmental Management
> University of Waterloo
> 200 University Ave. W - Waterloo, ON - Canada N2L 3G1
> http://www.fes.uwaterloo.ca/geography/faculty/brenning/
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
More information about the R-sig-Geo
mailing list