0

I have a raster file for the whole world whose details are:

class       : RasterLayer 
dimensions  : 18000, 43200, 777600000  (nrow, ncol, ncell)
resolution  : 0.008333333, 0.008333333  (x, y)
extent      : -180, 180, -60, 90  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs 
data source : E:\bc26pr50\bc26pr501.tif 
names       : bc26pr501 
values      : 0, 1100  (min, max)

And I want to subset it to mimic another raster file which is only for US:

class       : RasterLayer 
dimensions  : 3500, 7000, 24500000  (nrow, ncol, ncell)
resolution  : 0.01, 0.01  (x, y)
extent      : -130, -60, 20, 55  (xmin, xmax, ymin, ymax)
coord. ref. : NA 
data source : E:\dem.tif 
names       : dem 
values      : -85.25208, 4385.539  (min, max)

How can I transform the resolution as well as subset the dataset? Do I have to use RGDAL for this? Any pointers would be helpful.

maximusdooku
  • 5,242
  • 10
  • 54
  • 94

2 Answers2

1

I'd suggest to use gdalwarp function in package gdalUtils. You'll need to set the "te" and "tr" parameters and maybe play a bit with "tap" but you should easily get what you want.

HTH,

Lorenzo

lbusett
  • 5,801
  • 2
  • 24
  • 47
0

First, use the crop() function from the raster package:

r1.crop <- crop(r1,r2) # probably not obligatory, but will speed up the next action

Then use the resample function

r1.resamp <- resample(r1.crop, r2) # can be slow

You should be very close to your objective. There may be more efficient ways but try this one first then optimize.

Bastien
  • 3,007
  • 20
  • 38