[R-sig-Geo] Generate a coordinate (latitude) image?

Marcelino de la Cruz marcelino.delacruz at upm.es
Wed May 18 15:15:31 CEST 2011


On 18/05/2011 1:25, Jonathan Greenberg wrote:
> Folks:
>
> Is there any way to take a raster and generate two outputs where
> each pixel is the center coordinate of that pixel (e.g. you will have
> one x- image and one y-image)?  I'm trying to produce a "latitude map"
> for solar calculations.
>
>    
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

> --j
>
>
>    


-- 
_________________________________ Marcelino de la Cruz Rot Departamento 
de Biologia Vegetal E.U.T.I. Agricola Universidad Politecnica de Madrid 
28040 Madrid Tel: 34913365654 _________________________________



More information about the R-sig-Geo mailing list