[R-sig-Geo] Problems with plotting large factor-type rasters using the raster package
Tomislav Hengl
hengl at spatial-analyst.net
Thu Jan 23 11:52:20 CET 2014
Hi Pascal,
Setting maxpixels works indeed (thanx for spotting this). Nevertheless,
I would adjust the code so that the "raster::image" method does not
break due to some invisible parameter.
T. (Tom) Hengl
Url: http://www.wageningenur.nl/en/Persons/dr.-T-Tom-Hengl.htm
Network: http://profiles.google.com/tom.hengl
Publications: http://scholar.google.com/citations?user=2oYU7S8AAAAJ
On 23-1-2014 11:12, Pascal Oettli wrote:
> Hello,
>
> You can set a larger number of pixels in the "image" function:
>
>> image(r2, maxpixels=5e6)
>
> Or I missunderstood the problem.
>
> Regards,
> Pascal
>
> On 23 January 2014 18:56, Tomislav Hengl <hengl at spatial-analyst.net> wrote:
>>
>> Hi Robert,
>>
>> I am having problems with plotting factor-type rasters using the raster
>> package (v. 2.1-49). Here is the error message I get:
>>
>> library(raster)
>> library(plotKML)
>> ## smaller raster:
>> data(eberg_grid)
>> gridded(eberg_grid) <- ~x+y
>> eberg_grid$CL <- cut(eberg_grid$DEMSRT6, breaks=c(200,250,300,350))
>> r <- raster(eberg_grid["CL"])
>> image(r, col=c("red","green","blue"))
>> ## This works fine; now lets try with a larger raster (>5e5 pixels):
>> sp <- SpatialPixelsDataFrame(spsample(eberg_grid, n=1e6, type="regular"),
>> data=data.frame(v=runif(1000^2)))
>> sp$CL <- cut(sp$v, breaks=c(0.1,0.2,0.3,0.4))
>> r2 <- raster(sp["CL"])
>> image(r2)
>>
>> Error in .checkLevels(levels(x)[[1]], value) :
>> new raster attributes (factor values) should be in a data.frame (inside a
>> list)
>>
>> Somehow, image function in the raster package does not want to plot large
>> rasters that are of factor type. I've looked at the source code
>> (https://r-forge.r-project.org/scm/viewvc.php/pkg/raster/R/image.R?view=markup&root=raster),
>> and it looks as the problem is with the "maxpixels" argument (if the new
>> raster has >5e5 pixels, the function breaks).
>>
>> thank you,
>>
>> T. (Tom) Hengl
>> Url: http://www.wageningenur.nl/en/Persons/dr.-T-Tom-Hengl.htm
>> Network: http://profiles.google.com/tom.hengl
>> Publications: http://scholar.google.com/citations?user=2oYU7S8AAAAJ
>>
>> _______________________________________________
>> 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