[R-sig-Geo] create raster using extent and resolution?

Agustin Lobo alobolistas at gmail.com
Fri Jul 15 21:12:07 CEST 2011


Barry,

I tried that first, but by some reason (my raster version?), the
result here is different than yours:
> CODEQP <- raster(extent(PNMlimit))
> show(CODEQP)
class       : RasterLayer
dimensions  : 10, 10, 100  (nrow, ncol, ncell)
resolution  : 2586.382, 1886.275  (x, y)
extent      : 438048.4, 463912.3, 4615552, 4634415  (xmin, xmax, ymin, ymax)
coord. ref. : NA
values      : none

> res(CODEQP)<-c(100,100)
> show(CODEQP)
class       : RasterLayer
dimensions  : 10, 10, 100  (nrow, ncol, ncell)
resolution  : 100, 100  (x, y)
extent      : 438048.4, 439048.4, 4633415, 4634415  (xmin, xmax, ymin, ymax)
coord. ref. : NA
values      : none

Note res() keeps the same nb. of pixels and changes (a lot) the extent.
In your example:
> a = raster(e)
> show(a)
class       : RasterLayer
dimensions  : 10, 10, 100  (nrow, ncol, ncell)
resolution  : 320, 460  (x, y)
extent      : 178400, 181600, 329400, 334000  (xmin, xmax, ymin, ymax)
coord. ref. : NA
values      : none

> res(a)=c(100,100)
> show(a)
class       : RasterLayer
dimensions  : 10, 10, 100  (nrow, ncol, ncell)
resolution  : 100, 100  (x, y)
extent      : 178400, 179400, 333000, 334000  (xmin, xmax, ymin, ymax)
coord. ref. : NA
values      : none

Agus

> sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i486-pc-linux-gnu (32-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8          LC_NUMERIC=C
LC_TIME=en_US.UTF-8
 [4] LC_COLLATE=en_US.UTF-8        LC_MONETARY=en_US.UTF-8
LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8          LC_NAME=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
[10] LC_TELEPHONE=en_US.UTF-8      LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] rgdal_0.6-31  raster_1.8-42 sp_0.9-83     rkward_0.5.6

loaded via a namespace (and not attached):
[1] grid_2.13.1     lattice_0.19-30 tools_2.13.1


Agus


2011/7/15 Barry Rowlingson <b.rowlingson at lancaster.ac.uk>:
> On Fri, Jul 15, 2011 at 12:00 PM, Agustin Lobo <alobolistas at gmail.com> wrote:
>> Hi!
>>
>> Is it possible to create a raster object using extent and resolution,
>> thus having
>> raster() to calculate the required nb. of rows and columns? Something like,
>>
>> a = raster (ext=miextent, res=100)
>>
>> (Obviously the nb. of pixels would have to be rounded)
>
> In two steps: create the raster and then set the resolution using "res<-"
>
>> e
> class       : Extent
> xmin        : 178400
> xmax        : 181600
> ymin        : 329400
> ymax        : 334000
>> a = raster(e); res(a)=c(100,100)
>> a
> class       : RasterLayer
> dimensions  : 46, 32, 1472  (nrow, ncol, ncell)
> resolution  : 100, 100  (x, y)
> extent      : 178400, 181600, 329400, 334000  (xmin, xmax, ymin, ymax)
> coord. ref. : NA
> values      : none
>
> - it chooses the dimensions, rounding if necessary.
>
> Barry
>
> _______________________________________________
> 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