Thiago,

This happens because you are using rasters with a different extent. The
compare function should do

 compare(amz, glb)

and then give an error and stop. I will add that right away. Thanks for
reporting.

I suppose what you want to do (first) is crop:

x = crop(glb, amz)

Robert

On Wed, Feb 8, 2012 at 11:41 AM, Thiago Veloso <thi_veloso@yahoo.com.br>wrote:

>  Dear list,
>
>  I am trying to combine two rasters. One raster has global coverage, while
> other covers only Amazon.
>
>  Let me show in pratice. First I create an emtpy structure with the
> intended domain (global) and resolution (0.5 degree):
>
> > library(raster)
> > glb<-raster(nrows=360,ncols=720,xmn=-180,xmx=180,ymn=-90,ymx=90)
> > glb[]<-NA
> > glb
> class       : RasterLayer
> dimensions  : 360, 720, 259200  (nrow, ncol, ncell)
> resolution  : 0.5, 0.5  (x, y)
> extent      : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> values      : in memory
> min value   : NA
> max value   : NA
>
>  On the other hand, I load a Amazon deforestation file which contains
> values between 0 and 1:
>
> > amz<-raster("/home/data/amz.img")
> > amz
> class       : RasterLayer
> dimensions  : 47, 65, 3055  (nrow, ncol, ncell)
> resolution  : 0.5, 0.5  (x, y)
> extent      : -74, -41.5, -17.5, 6  (xmin, xmax, ymin, ymax)
> coord. ref. : NA
> values      : /home/data/amz.img
> min value   : 0
> max value   : 1
>
>  Next, I apply the same projection:
>
> > projection(amz) <- projection(glb)
> > amz
> class       : RasterLayer
> dimensions  : 47, 65, 3055  (nrow, ncol, ncell)
> resolution  : 0.5, 0.5  (x, y)
> extent      : -74, -41.5, -17.5, 6  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> values      : /home/data/amz.img
> min value   : 0
> max value   : 1
>
>  Last, after trying to replace NA values in the global raster with the
> values of the amazon object,
>
> > result <- cover(glb,amz)
>
>  a erratic stripe across the globe is produced, like showed in this image:
> http://img269.imageshack.us/img269/1328/errorau.png
>
>  Does anyone have a suggestion to solve this problem?
>
>  Thanks in advance,
>  Thiago.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]

