[R-sig-Geo] Create raster based on overlapping

Rafael Wüest rafael.wueest at wsl.ch
Wed Aug 8 16:11:04 CEST 2012


Hi Thiago

I am not exactly sure whether I understand what you need (what do you mean by 'touched'). Anyway, the resample command may help you. Something like
resample(r2,r1) may get you close. Try the different method options...

If this doesn't do the job, the less elegant option may be:

dat<-extract(r2,rasterToPolygons(r1))
cells<-sapply(dat,function(x) all(is.na(x)))
r1[cells]<-NA

HTH,
Rafi


On 08.08.2012, at 15:17, Thiago Veloso wrote:

>  Dear all,
>   
>  I have two rasters: r1 is a 0.5 degree netcdf file produced by a vegetation model. r2 is a 30m shapefile which I rasterized to a raster with the same 30m resolution. r2 values are all NA and 1.
> 
>  Please see below:
> 
>> r1
> class       : RasterLayer 
> dimensions  : 10, 18, 180  (nrow, ncol, ncell)
> resolution  : 0.5, 0.5  (x, y)
> extent      : -53, -44, -25, -20  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
> values      : in memory
> layer name  : variable 
> zvar        : variable 
> 
>> r2
> class       : RasterLayer 
> dimensions  : 14469, 22190, 321067110  (nrow, ncol, ncell)
> resolution  : 0.0002702699, 0.0002702702  (x, y)
> extent      : -52.60649, -46.6092, -23.7172, -19.80666  (xmin, xmax, ymin, ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
> values      : in memory
> layer name  : cs_2005spx1 
> min value   : 1 
> max value   : 1 
> 
>  Here you can see a join plot: http://img855.imageshack.us/img855/2820/plotzoom.png
> 
>  Is it possible to create a new raster, which is composed only by r1 cells which are "touched" by r2 cells?
> 
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



--
Rafael Wüest
Swiss Federal Research Institute WSL
Zürcherstrasse 111
8903 Birmensdorf
Switzerland

+41 44 7392126
rafael.wueest at wsl.ch
http://www.wsl.ch/info/mitarbeitende/wueest/index_EN



More information about the R-sig-Geo mailing list