Thursday, 7 January 2016

raster - R giving error when attempting map algebra


I'm trying to manipulate some downloaded rasters using R, and keep getting the same error when I try to do any type of map algebra.


The example below uses a raster file downloaded from http://www.csc.noaa.gov/digitalcoast/data/ccapregional/ geotiff and .grd files, regardless of whether I downloaded them or generated them previously.


require(raster)
test1=raster("nh_2006_ccap_land_cover.img")

test2=test1+1

Gives the error:


Error in matrix(unlist(ini), ncol = 2, byrow = TRUE) : 
'data' must be of a vector type, was 'NULL'
In addition: There were 11 warnings (use warnings() to see them)

On the other hand, I'm not encountering problems with map algebra for rasters generated on the fly. So I'm not having any problems with this example from the documentation:


r1 <- raster(ncols=10, nrows=10)
r1[] <- runif(ncell(r1))

r2 <- setValues(r1, 1:ncell(r1) / ncell(r1) )
r3 <- r1 + r2
r2 <- r1 / 10
r3 <- r1 * (r2 - 1 + r1^2 / r2)
plot(r3)

What's going on here?



Answer



The problem was that I had run out of space to write to disk, and the map algebra commands I was using were attempting to generate and write large temporary raster files.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...