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

Robert Hijmans r.hijmans at gmail.com
Wed May 18 18:36:16 CEST 2011


> 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. 
>
> --j 


Jonathan, 

If your data are in lon/lat

r <- raster()
x <- init(r, v='x')
y <- init(r, v='y')


Or "by hand", for lon/lat do

lat <- yFromRow(r, 1:nrow(r))

if the raster is not lon/lat

xy <- SpatialPoints(xyFromCell(r, cellFromRowCol(1:nrow(r), 1)))
lat <- coordinates( spTransform(xy, CRS( +proj=longlat +datum=WGS84 )))[,2] 

In cases like this, I stop here. Rather than making a latitude raster with
lots of repeated values, I would work with the lat vector. But you could do
something like this:

x <- t((t(r) * lat))
plot(x)


Best, Robert
 

--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Generate-a-coordinate-latitude-image-tp6375697p6378473.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list