Skip to content
Prev 26569 / 29559 Next

Extract xy coordinates from raster of interesting neighborhood cells

Thanks so much Vijay and Ben, now it works!!!

 ??????????? Originally, I expect 24 for each 4 point (96 total). 
Apologies, in my example preparation I changed the raster objects 
'land_mask' and 'r' and the idea of my second point [45.12069, 
-88.369745] is to force NA results.

 ??????????? The code below is a solution that I expected:

### Alternative to what Ben suggested!
## Set neighborhood matrix.? Focal cell is 0 while neighbors are 1!!
neigh <- matrix(1L, nrow=5, ncol=5); neigh[3,3] <- 0L
e1<-adjacent(r, N_cells , directions=neigh, pairs=FALSE)
ng_coords1 <- xyFromCell(r, e1)
plot(r);
points(pts, col='red', pch=16);
points(ng_coords, col='black', pch=16);
points(ng_coords1, col='blue', pch=16)
### END