[R-sig-Geo] Reproject raster from 0 360 to -180 180?
Jorge Molinos
Jorge.Molinos at sams.ac.uk
Wed Jul 10 10:12:02 CEST 2013
Thanks a lot! Exactly what I needed.
Jorge
-----Original Message-----
From: r-sig-geo-bounces at r-project.org [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of Kranstauber, Bart
Sent: 10 July 2013 07:36
Cc: r-sig-geo at r-project.org
Subject: Re: [R-sig-Geo] Reproject raster from 0 360 to -180 180?
Use rotate in the package raster see for example:
https://stat.ethz.ch/pipermail/r-sig-geo/2011-March/011155.html
Bart
On 07/09/2013 11:59 PM, Jorge Molinos wrote:
> Hello everybody,
>
> I have a raster that has longtitudes from 0 to 360 with the horizontal
> center at 180 longtitude
>
> http://www.freeimagehosting.net/lr9rb
>
> Pre_CCSM_r
> class : RasterLayer
> dimensions : 395, 320, 126400 (nrow, ncol, ncell) resolution :
> 1.125, 0.4294937 (x, y)
> extent : 0.50001, 360.5, -79.43527, 90.21475 (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 data source : in memory
> names : layer
> values : 271.2439, 303.2426 (min, max)
>
> I want to transform this to a new raster with -180, 180 longtitude
> range centred at Greenwich meridian (0) for comparisons/analysis with
> other raster files. I have tried cutting the original raster into two
> (using the meridian 180 as cutting value) and piece them back together
> but got sort of a mosaic raster instead
>
> http://www.freeimagehosting.net/h5bxo
>
>> lonlat <- data.frame(xyFromCell(Pre_CCSM_r, 1:ncell(Pre_CCSM_r)))
>> lonlat <- cbind(lonlat, getValues(Pre_CCSM_r))
>> head(lonlat)
> x y getValues(Pre_CCSM_r)
> 1 1.06251 90 271.3698
> 2 2.18751 90 271.3698
> 3 3.31251 90 271.3698
> 4 4.43751 90 271.3698
> 5 5.56251 90 271.3698
> 6 6.68751 90 271.3698
>
>> lolaA <- as.matrix(lonlat[lonlat$x>180,]) lolaB <-
>> as.matrix(lonlat[lonlat$x<=180,]) mydata <- rbind(lolaA,lolaB) mydat
>> <- matrix(mydata[,3], ncol=320,nrow=395,byrow=T) Pre_Had <-
>> raster(mydat,xmn=-180, xmx=180, ymn=-90, ymx=90,crs="+proj=longlat
>> +datum=WGS84")
>
> This is probably a very clumsy (obviously wrong) way of doing it so any help/advice will be very much appreciated.
>
> Thanks!!
>
> Jorge
>
>
>
>
>
>
>
>
> The Scottish Association for Marine Science (SAMS) is registered in Scotland as a Company Limited by Guarantee (SC009292) and is a registered charity (9206). SAMS has an actively trading wholly owned subsidiary company: SAMS Research Services Ltd a Limited Company (SC224404). All Companies in the group are registered in Scotland and share a registered office at Scottish Marine Institute, Oban Argyll PA37 1QA. The content of this message may contain personal views which are not the views of SAMS unless specifically stated. Please note that all email traffic is monitored for purposes of security and spam filtering. As such individual emails may be examined in more detail.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
The Scottish Association for Marine Science (SAMS) is registered in Scotland as a Company Limited by Guarantee (SC009292) and is a registered charity (9206). SAMS has an actively trading wholly owned subsidiary company: SAMS Research Services Ltd a Limited Company (SC224404). All Companies in the group are registered in Scotland and share a registered office at Scottish Marine Institute, Oban Argyll PA37 1QA. The content of this message may contain personal views which are not the views of SAMS unless specifically stated. Please note that all email traffic is monitored for purposes of security and spam filtering. As such individual emails may be examined in more detail.
More information about the R-sig-Geo
mailing list