Dear list members, I have a forest layer and an empty raster. I would like to compute for each raster cell the percentage of forest in a set radius around the center of the cell. I used the option ?getCover? of the function rasterize but it only returns the fraction of each grid cell that is covered by the polygons of forest. Is there a way to do that in R? The forest data can be downloaded here: https://drive.google.com/folderview?id=0Bwf27qBU9Q1ONGpxSHFIbE9xRkk&usp=sharing library(raster) library(rgdal) # forest data forest <- readOGR(dsn = path1, layer = "foretze") # raster set Xmin <- c(795800) Xmax <- c(840200) Ymin <- c(2143600) Ymax <- c(2186900) rr <- raster(nrows=866, ncols=888, crs=CRS("+init=epsg:27572"), xmn=Xmin, xmx=Xmax, ymn=Ymin, ymx=Ymax) pforest <- rasterize(forest, rr, getCover=T) Many thanks! Jeremy
Percentage of forest cover in a set radius for each raster cell
2 messages · Jeremy Larroque, Tim Meehan
you could check out the focal() function in the raster package: 1) turn your forest layer into a layer of 1 (presence) and 0 (absence) 2) use the function to sum the number of ones within a neighborhood of each focal cell 3) convert the focal sum to an area 4) divide the area by the total possible area of the buffer best, tim On Sun, Jan 24, 2016 at 1:58 PM, Jeremy Larroque <larroque.jeremy at gmail.com> wrote:
Dear list members, I have a forest layer and an empty raster. I would like to compute for each raster cell the percentage of forest in a set radius around the center of the cell. I used the option ?getCover? of the function rasterize but it only returns the fraction of each grid cell that is covered by the polygons of forest. Is there a way to do that in R? The forest data can be downloaded here: https://drive.google.com/folderview?id=0Bwf27qBU9Q1ONGpxSHFIbE9xRkk&usp=sharing library(raster) library(rgdal) # forest data forest <- readOGR(dsn = path1, layer = "foretze") # raster set Xmin <- c(795800) Xmax <- c(840200) Ymin <- c(2143600) Ymax <- c(2186900) rr <- raster(nrows=866, ncols=888, crs=CRS("+init=epsg:27572"), xmn=Xmin, xmx=Xmax, ymn=Ymin, ymx=Ymax) pforest <- rasterize(forest, rr, getCover=T) Many thanks! Jeremy [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo