[R-sig-Geo] create a raster with values from SpatialPolygonsDataFrame
Benjamin Mack
bmack at uni-bonn.de
Mon Nov 7 17:52:57 CET 2011
Hello list,
I would like to create a new raster with values from a
SpatialPolygonsDataFrame. It works with the code below, however it is
really slow. I would appreciate any suggestions which could speed up the
code!
Thanks in advance!
Ben
Code:
"r" is the raster file
"ref" is the SpatialPolygonsDataFrame with one column named "lc" with
integer values.
to write the values from the polygons to the raster I do the following:
u.IDs <- unique(ref at data$lc) # unique lc(land cover) values/IDs
for (ii in 1:length(u.IDs)) {
temp <- ref[ref at data$lc==u.IDs[ii],] # create a new
SpatialPolygonsDataFrame for a specific lc-ID
ra[temp] <- u.IDs[ii] # write the values to the raster }
More information about the R-sig-Geo
mailing list