# Extract xy coordinates from raster of interesting neighborhood cells

4 messages
Open this post in threaded view
|

## Extract xy coordinates from raster of interesting neighborhood cells

 Dear R-Sig-Geo Members,      I've like to extract xy coordinates from raster of 24 neigborhood cells that surround the 4 given points (pts_s) pixels and for this I used: #Packages require(raster) require(sp) ## Create a raster r <- raster(nc=30, nr=30) r <- setValues(r, round(runif(ncell(r))* 255)) plot(r) ##Given interesting points coordinates xd     <- c(-24.99270,45.12069,99.40321,73.64419) yd  <- c(-45.435267,-88.369745,-7.086949,44.174530) pts <- data.frame(xd,yd) pts_s<- SpatialPoints(pts) points(pts_s, col="red", pch=16) ## Find pixels center of each point (My idea is not to use the original point coordinates, but coordinates of the center of interesting pixel). N_cells <- cellFromXY(r, pts_s) # Extract xy coordinates from raster of 24 neighborhood cells given pixel number N_cells e<-adjacent(r, N_cells , directions='bishop', id=TRUE) coordinates(land_mask)[e[,1],] ## Doesn't return 24 neighborhood by N_cells object ng_coords<-coordinates(land_mask)[e[,1],] # #Visualization plot(r) points(pts_s, col="red", pch=16) points(ng_coords, col="black", pch=16) ##      But I don't have success because the ng_coords object is not a 24 neighborhood cells of each point that I search. There are solution for this? Thanks in advance, Alexandre -- ====================================================================== Alexandre dos Santos Proteção Florestal IFMT - Instituto Federal de Educação, Ciência e Tecnologia de Mato Grosso Campus Cáceres Caixa Postal 244 Avenida dos Ramires, s/n Bairro: Distrito Industrial Cáceres - MT                      CEP: 78.200-000 Fone: (+55) 65 99686-6970 (VIVO) (+55) 65 3221-2674 (FIXO)          [hidden email] Lattes: http://lattes.cnpq.br/1360403201088680OrcID: orcid.org/0000-0001-8232-6722 Researchgate: www.researchgate.net/profile/Alexandre_Santos10 LinkedIn: br.linkedin.com/in/alexandre-dos-santos-87961635 Mendeley:www.mendeley.com/profiles/alexandre-dos-santos6/ _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Open this post in threaded view
|