[R-sig-Geo] re-projecting raster brick, output has no values

Robert J. Hijmans r.hijmans at gmail.com
Sun Mar 23 06:31:08 CET 2014


Matt,

The x (longitude) coordinates are not valid for lat/lon. It looks like
they are using 0 to 360 instead of -180 to 180 ---- which is what
climate modelers do. For global datasets you can use 'rotate' to fix
this, but that function does not (yet) work for smaller extents. In
this case you can fix the problem with the shift function, as in the
example below that puts the raster in Oregon (which I am assuming is
where it should be).

library(raster)
r <- raster(nrow=121, ncol=121, xmn=237.9958, xmx=239.0041,
ymn=43.99583, ymx=45.00413)
values(r) <- 1:ncell(r)
x <- shift(r, -360)

utmproj <- "+proj=utm +zone=10 +ellps=GRS80 +units=m +no_defs"
p <- projectRaster(x, res=800, crs=utmproj, method="bilinear")
p

Robert



On Sat, Mar 22, 2014 at 9:06 PM, Matthew Cooper <mguycooper at gmail.com> wrote:
> Hi all,
>
> I have created a raster brick and the data is in lat/long coordinate
> system. I would like to re-project the brick to UTM and then save the data.
> The output of my code gives me NA and -Inf for the values of the
> re-projected raster brick:
>
> install.packages("rgdal")
> install.packages("raster")
> install.packages("sp")
> library(rgdal)
> library(raster)
> library(sp)
>
> f <- "K:/PRISM_US800m_2010edition/ppt_east_prism.nc"
> b <- brick(f,lvar=4)
> NAvalue(b) <- -1e+34
>
> b
>
> class       : RasterBrick
> dimensions  : 121, 121, 14641, 348  (nrow, ncol, ncell, nlayers)
> resolution  : 0.008333, 0.008333  (x, y)
> extent      : 237.9958, 239.0041, 43.99583, 45.00413  (xmin, xmax, ymin,
> ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> data source : K:\PRISM_US800m_2010edition\ppt_east_prism.nc
> names       : X1981.04162597656, X1981.125, X1981.20837402344,
> X1981.29174804688, X1981.375, X1981.45837402344, X1981.54174804688,
> X1981.625, X1981.70837402344, X1981.79174804688, X1981.875,
> X1981.95837402344, X1982.04174804688, X1982.125, X1982.20837402344, ...
> year        : 1981.04162597656, 2009.95837402344 (min, max)
> varname     : PPT_EAST
>
> utmproj <- "+proj=utm +zone=10 +ellps=GRS80 +units=m +no_defs"
> bnew <-
> projectRaster(b,res=800,crs=utmproj,method="bilinear",alignOnly=FALSE,over=FALSE)
>
>  bnew
> class       : RasterBrick
> dimensions  : 152, 113, 17176, 348  (nrow, ncol, ncell, nlayers)
> resolution  : 800, 800  (x, y)
> extent      : 574481.3, 664881.3, 4867763, 4989363  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=utm +zone=10 +ellps=GRS80 +units=m +no_defs
> data source : in memory
> names       : X1981.04162597656, X1981.125, X1981.20837402344,
> X1981.29174804688, X1981.375, X1981.45837402344, X1981.54174804688,
> X1981.625, X1981.70837402344, X1981.79174804688, X1981.875,
> X1981.95837402344, X1982.04174804688, X1982.125, X1982.20837402344, ...
> min values  :                NA,        NA,                NA,
>    NA,        NA,                NA,                NA,        NA,
>        NA,                NA,        NA,                NA,
>  NA,        NA,                NA, ...
> max values  :                 ?,         ?,                 ?,
>     ?,         ?,                 ?,                 ?,         ?,
>         ?,                 ?,         ?,                 ?,
> ?,         ?,                 ?, ...
>
> Any ideas? Thank you.
>
> Matt
>
> --
> *Matt Cooper*
> Water Resources Graduate Program
> College of Earth, Ocean and Atmospheric Sciences
> Oregon State University
>
> (831) 566 9149
> matthew.cooper at geo.oregonstate.edu
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list