Converting SpatialPointsDataFrame to SpatialGridDataFrame
On Thu, 11 Jun 2009, Rainer M Krug wrote:
Hi
I spend the whole day with it, trying grass, gdal, R, but was not successful
(and I know it can be done...).
I have a shape file and a raster file, both in the same projection and in
thew same area (shape file completely overlapping the raster) and I want to
"burn" the values from one column in the attribute table of the shape file
(DNSTY) into the raster.
I am doing the following:
####
library(sp)
library(maptools)
library(raster) # <- this might work as well. I also have the shape file as
a .csv file, including coordinates and DNSTY
s <- readShapePoints("./plants.shp")
r <- readAsciiGrid("./plants.asc")
## and now?
####
I seem to remember that it works by using overlay(), but I don't remember
how.\
Please see the thread started by Karla Falk yesterday. overlay() will tell you which raster cells the points fall in, but you cannot just "burn" across unless you know definitely that hit raster cells have only one hit, otherwise you'll need tapply (or table for counting) to tally the point values by hit cell. I think that is the step you need to add. It'll take some attempts to find a recipe that works for your specific case, it usually does, but then works. Roger
Also, it should be working with pointsToRaster() from the package raster, but I also was not successful. Cheers, Rainer
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