Given raster
object r
, how can I create a new raster with the same extent and resolution, with cell values equal to the latitude (or longitude) of the corresponding cell in r
?
For example, r
might look like:
r <- raster(matrix(runif(100), ncol=10))
If your question is about create a new raster object which has the same extent and resolution of another raster object you can use command template
template
is Raster* or Extent object used to set the extent (and CRS in case of a Raster* object). If not NULL, arguments xmn, xmx, ymn, ymx and crs (unless template is an Extent object) are ignored
r <- raster(matrix(runif(100), ncol=10))
r1 <- raster(x, template=r)