reprojrecting longitude from 0 - 360 to -180 - 180

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

reprojrecting longitude from 0 - 360 to -180 - 180

John Wasige
Hello r community,

This is to request for help on how to reprojrect longitude from 0 - 360 to
-180 - 180
With the following script below, i get output transformed to something like
rectangle. Is there a better way of doing it?
### script
convert longitude from 0 - 360 to -180 - 180
library(raster)
rst <- raster('D:/prec/b1980p.tif')
rst <- raster(matrix(1:100, ncol=10), 0, 360, -90, 90, crs="+proj=merc")
r2 <- rotate(rst)
r2

Thanks for your help

John

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: reprojrecting longitude from 0 - 360 to -180 - 180

Michael Sumner-2
On Wed Feb 04 2015 at 5:10:02 AM John Wasige <[hidden email]> wrote:

> Hello r community,
>
> This is to request for help on how to reprojrect longitude from 0 - 360 to
> -180 - 180
> With the following script below, i get output transformed to something like
> rectangle. Is there a better way of doing it?
> ### script
> convert longitude from 0 - 360 to -180 - 180
> library(raster)
> rst <- raster('D:/prec/b1980p.tif')
>

I'm confused as why you load from file, but then overwrite that result with
the next line below


> rst <- raster(matrix(1:100, ncol=10), 0, 360, -90, 90, crs="+proj=merc")
>

"+proj=merc" is completely incompatible with an extent in longitude and
latitude - merc is Mercator, which is a metre-based projection by default,
with this PROJ.4 string. If you literally mean 0-360 on WGS84 (for example)
then you should use

, crs = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0
+over"

(+over indicates that you cross the dateline, but its use/application is
not seamless)

If you apply the Mercator projection to xmn=0, xmx=360, ymn=-90, ymx=90 you
are specifying a 360 x 180 metre region in the Atlantic ocean. For example

library(raster)
library(rgdal)
## project just the extent of this raster to longlat
projectExtent(rst, "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs
+towgs84=0,0,0 +over")
class       : RasterLayer
dimensions  : 10, 10, 100  (nrow, ncol, ncell)
resolution  : 0.0003233935, 0.0001627865  (x, y)
extent      : 0, 0.003233935, -0.0008139325, 0.0008139325  (xmin, xmax,
ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs
+towgs84=0,0,0 +over


r2 <- rotate(rst)
> r2
>
>
The function raster::rotate is intended purely for the longlat case 0,360
modified to -180,180 - it does "work" for other cases but it's not
guaranteed to - and it's not written in a general way for other cases.

Hope that clarifies a few things, also please use the R-Sig-Geo mailing
list for a group more relevant to these topics.

Cheers, Mike.


> Thanks for your help
>
> John
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.