Skip to content
Prev 11730 / 29559 Next

Generate a coordinate (latitude) image?

On 18/05/2011 1:25, Jonathan Greenberg wrote:
If you mean "each pixel value  is the center coordinate of that pixel" 
you could proceed like this:

# (first, I built a raster for my toy example)
library(maptools)
data(meuse.grid) # only the non-missing valued cells
coordinates(meuse.grid) = c("x", "y") # promote to SpatialPointsDataFrame
gridded(meuse.grid) <- TRUE # promote to SpatialPixelsDataFrame

# now, assign the coordinates as values to each pixel
meuse.grid[["xcoord"]] = coordinates(meuse.grid)[,"x"]
meuse.grid[["ycoord"]] = coordinates(meuse.grid)[,"y"]

image(meuse.grid["xcoord"]) # note the single [
image(meuse.grid["ycoord"])

Cheers,
  Marcelino