简体   繁体   中英

Extract buffer from a raster in R

I am beginner in R and spatial analysis. I have a raster where the cells of habitat polygons are equal to 1.

 img <- readPNG("Paysage.png")
 map <- raster(img[,,2],xmn=0, xmx=999, ymn=0, ymx=999)
 projection(map) <- "+proj=utm +zone=18 +ellps=GRS80 +datum=NAD83 +units=m +no_defs"
 map[] <- polygons[,c("id_polygon")] 
 map[ map > 0] <- 1

From this raster, how can I build, for each polygon, a raster in which all polygon cells that are situated in a buffer of 1 km around a given polygon are equal to 1 and all other matrix cells are equal to 0.

Thanks very much for your help.

Use the buffer function in the raster package: Just make sure you set to NA all of the cells that you do not want to have the buffer grow from:

map[map==0]=NA
library(raster)
b <- buffer(map, width=1000) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM