Whenever I rasterize my SpatialPolygonsDataFrame, I lose the attribute / data information part. The command "rasterize" is from the package "raster" in R.
I have the following RasterLayer (named "raster1")
class : RasterLayer
dimensions : 6000, 4800, 28800000 (nrow, ncol, ncell)
resolution : 0.00025, 0.00015 (x, y)
extent : 8.699875, 9.899875, 46.69993, 47.59993 (xmin, xmax, ymin, ymax)
coord. ref. : +init=epsg:3857 +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs
My SpatialPolygonsDataFrame (named "bw1") has the following properties
class : SpatialPolygonsDataFrame
features : 7663
extent : 980075.6, 1076577, 5908811, 6023151 (xmin, xmax, ymin, ymax)
coord. ref. : +init=epsg:3857 +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs
variables : 2
names : A, B
min values : 3231, 11
max values : 3955, 19
When I use a the command
bw1_raster<-rasterize(bw1,raster1,fun='last',field=c("A","B")
I get the new object "bw1_raster":
class : RasterLayer
dimensions : 6000, 4800, 28800000 (nrow, ncol, ncell)
resolution : 0.00025, 0.00015 (x, y)
extent : 8.699875, 9.899875, 46.69993, 47.59993 (xmin, xmax, ymin, ymax)
coord. ref. : +init=epsg:3857 +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0
+lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs
data source : in memory
names : layer
values : NA, NA (min, max)
How do I get a raster object with attributes / layers "A" and "B"?