Skip to content

Turning SpatialPointsDataFrame to Raster using rasterize

5 messages · Lionel, Jon Olav Skoien, Robert J. Hijmans

#
Lionel,

You are not providing a reproducible example (y70 is not given), and you 
are not telling the versions of R and the packages you are using, so I 
am not sure if my comments here will solve your case.

1. The issue with the lines is difficult to answer without knowing more, 
but it could be a version issue. At least one of the older R-versions (I 
think it was one of the 2.14-versions) tended to add white lines to many 
gridded plots. Try with a more current version if this could be your case.

2. For the disappearing points, you might end up with more than 
observation location in some of the raster cells. rasterize will compute 
the cell value from the fun argument, and rasterToPoints will only 
return one point back. In the example below, 10 rows of meuse have been 
duplicated before the second call to rasterize and rasterToPoints. You 
can see that it returns only the original 155 points in this case. If 
meuse.grid had been coarser, also mnew would have fewer point than the 
original meuse-object. You can check how many points you have within the 
distance of a grid cell with zerodist().

loadMeuse()
r = raster(meuse.grid)
ras = rasterize(meuse, r)
mnew = rasterToPoints(ras, spatial = TRUE)
summary(meuse)

meuse = rbind(meuse, meuse[1:10,])
ras = rasterize(meuse, r)
mnew2 = rasterToPoints(ras, spatial = TRUE)
summary(meuse)
summary(mnew)
summary(mnew2)

Cheers,
Jon
On 01-Feb-13 13:32, Lionel Hertzog wrote:

  
    
2 days later