[R-sig-Geo] Problem with raster

Robert J. Hijmans r.hijmans at gmail.com
Fri Feb 21 18:15:01 CET 2014


Mark,

You would not be tell from the error message, but the error occurs
because you are using an invalid CRS.
It should be:

proj4string=CRS("+proj=longlat")

instead of this:

proj4string=CRS("longlat")

Robert


On Fri, Feb 21, 2014 at 6:59 AM, Mark Payne <markpayneatwork at gmail.com> wrote:
> Hi,
>
> I am having a problem with the following code - I'm trying to create a
> raster from a SpatialGrid, but there seems to be something going wrong
> along the way - the problem pops up when I try to build two
> rasterlayers into a brick:
>
>> halfrect.grd <- GridTopology(c(-22.75,36.75),
> +                              c(0.5,0.5),
> +                              c(46,55))
>> grd.sp <- SpatialGrid(halfrect.grd,proj4string=CRS("+longlat"))
>> grd.r <- raster(grd.sp)
>> brick(grd.r,grd.r)
> class       : RasterBrick
> dimensions  : 55, 46, 2530, 1  (nrow, ncol, ncell, nlayers)
> resolution  : 0.5, 0.5  (x, y)
> extent      : -23, 0, 36.5, 64  (xmin, xmax, ymin, ymax)
> coord. ref. : +longlat
>
> This works ok so far. But then if I try to change the value, it fails
>
>> EP.r <- grd.r
>> EP.r[] <- NA
>> brick(EP.r,EP.r)  #Doesn't
> Error in x[, 2] : subscript out of bounds
>> values(EP.r) <- NA
>> brick(EP.r,EP.r)  #Doesn't
> Error in x[, 2] : subscript out of bounds
>>
>
> My package details are below. Does anyone have any ideas what could be
> going wrong?
>
> Mark
>
>> packageDescription("raster")
> Package: raster
> Type: Package
> Title: raster: Geographic data analysis and modeling
> Version: 2.2-12
> Date: 2014-1-17
> <snip>
>
>> R.version
>                _
> platform       x86_64-pc-linux-gnu
> arch           x86_64
> os             linux-gnu
> system         x86_64, linux-gnu
> status
> major          3
> minor          0.1
> year           2013
> month          05
> day            16
> svn rev        62743
> language       R
> version.string R version 3.0.1 (2013-05-16)
> nickname       Good Sport
>>
>
> _______________________________________________
> 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