[R] Warning message with "projectRaster" (package "raster"): 'from' has no cell values

Marine Regis marine.regis at hotmail.fr
Sat Mar 12 20:27:42 CET 2016


Hello,



I have two rasters with different resolution and projection.



> r1

class       : RasterLayer

dimensions  : 2510, 5233, 13134830  (nrow, ncol, ncell)

resolution  : 56, 56  (x, y)

extent      : 503198, 796246, 4917498, 5058058  (xmin, xmax, ymin, ymax)

coord. ref. : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0

data source : in memory

names       : layer

values      : 1, 8  (min, max)



> r2

class       : RasterBrick

dimensions  : 3250, 6570, 21352500, 1  (nrow, ncol, ncell, nlayers)

resolution  : 30, 30  (x, y)

extent      : 265380.5, 462480.5, 4984457, 5081957  (xmin, xmax, ymin, ymax)

coord. ref. : +proj=tmerc +lat_0=0 +lon_0=-73.5 +k=0.9999 +x_0=304800 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs

data source : H:\users\rast_temp.tif

names       : rast_temp



My objective is to merge the two rasters into a single raster. As the two rasters have different resolution and projection, I have used the function projectRaster (package raster) like this:


r <- projectRaster(from=r1, to=r2, method="ngb", alignOnly=TRUE)



However, I got this warning message:



Warning message:

In projectRaster(x, crs = projection(y)) : 'from' has no cell values



and yet, the two rasters have values:



> hasValues(r1)

[1] TRUE



> hasValues(r2)

[1] TRUE



When I remove the argument "alignOnly=TRUE", the code seems to work but I don't want that r1 has the same projected extent than r2 (I want to keep the original extent of r1).



Why do I get this warning message ?



Thank you very much for your help.

Marine


	[[alternative HTML version deleted]]



More information about the R-help mailing list