Thank you Robert,
but I run in some problems now...
I have installed the new raster package but now I cannot create a 
RasterLayer object from it.
 >   img <- stack("TSX_R2_overlap_all")
Fehler in .rasterObjectFromFile(x, band = band, objecttype = 
"RasterLayer",  :
Cannot create a RasterLayer object from this file.
(This is the Raster from which I take the resolution and and the extend 
for the task discussed here)
I also updated my R version (I used 2.11.1 before where everything 
worked fine) to the new one, and updated all packages, but the same 
error occurs.
Does anybody know what is wrong here. It is strange because before 
everything worked with the same code.

Thanx,
Benjamin



Am 07.11.2011 18:17, schrieb Robert J. Hijmans:
> Benjamin,
>
> You can do:
>
> x <- rasterize(r, ref, 'lc')
>
> If that is too slow you may try (with the current version of raster):
>
> x <- raster:::.p3r(r, ref, 'lc')
>
> (this is a function under development that is not well tested and will 
> disappear in the future, to replace rasterize)
>
> Robert
>
> On Mon, Nov 7, 2011 at 8:52 AM, Benjamin Mack <bmack@uni-bonn.de 
> <mailto:bmack@uni-bonn.de>> wrote:
>
>     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@data$lc) # unique lc(land cover) values/IDs
>      for (ii in 1:length(u.IDs)) {
>          temp <- ref[ref@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  }
>
>     _______________________________________________
>     R-sig-Geo mailing list
>     R-sig-Geo@r-project.org <mailto:R-sig-Geo@r-project.org>
>     https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>


-- 
Benjamin Mack
University of Bonn
Institute of Geodesy and Geoinformation
Nussallee 15
53115 Bonn
Germany

phone: +49 228 73-2711
fax: +49 228 73-2712


	[[alternative HTML version deleted]]

