1

I have imported a clipped raster (performed in ArcGIS 10.1) from the National Landcover Dataset into R, but when I try to plot I get the following error message.

Error in .readCellsGDAL(x, uniquecells, layers) : NAs are not allowed in subscripted assignments In addition: Warning message: In .readCells(x, cells, 1) : NAs introduced by coercion

I am relatively new to using rasters in R, but I cannot locate the NAs. levels(nlcd) yields the following:

ID  objectID    Value   Count   Red Green   Blue    Land_Cover_Class    opacity
0   1   0   4   0   0   0   Unclassified    1
1   12  11  584837  0.2784314   0.4196078   0.627451    Open Water  1
2   22  21  2247379 0.8666667   0.7882353   0.7882353   Developed, Open Space   1
3   23  22  954664  0.8470588   0.5764706   0.5098039   Developed, Low Intensity    1
4   24  23  647735  0.9294118   0   0   Developed, Medium Intensity 1
5   25  24  333254  0.6666667   0   0   Developed, High Intensity   1
6   32  31  12173780    0.6980392   0.6784314   0.6392157   Barren Land 1
7   42  41  5640937 0.4078431   0.6666667   0.3882353   Deciduous Forest    1
8   43  42  6987282 0.1098039   0.3882353   0.1882353   Evergreen Forest    1
9   44  43  957021  0.7098039   0.7882353   0.5568627   Mixed Forest    1
10  53  52  56354805    0.8 0.7294118   0.4862745   Shrub/Scrub 1
11  72  71  9100560 0.8862745   0.8862745   0.7568627   Herbaceuous 1
12  82  81  477862  0.8588235   0.8470588   0.2352941   Hay/Pasture 1
13  83  82  453351  0.6666667   0.4392157   0.1568627   Cultivated Crops    1
14  91  90  2671979 0.7294118   0.8470588   0.9176471   Woody Wetlands  1
15  96  95  495808  0.4392157   0.6392157   0.7294118   Herbaceuous wetlands    1

The only issue I can see being the problem is the first row.

Below is the code that I used.

library(rgdal) ## spatial
library(raster) ## spatial
library (rgeos) ## spatial
nlcd = raster("C:/Extract_img11.tif")
plot(nlcd)

I can't post Extract_img11.tif because it is too large.

Sorry for the vagueness of this question. My guess is that the clipping created the problem, but I haven't ever seen this before.

Thanks for any information.

  • Please show all the code used. Can you point to an example file. – mdsumner Jul 19 '14 at 5:03
  • Please update me if you solve this. Alejandro – user36434 Aug 31 '14 at 2:41
  • I had the same problem. I quickly realized that in fact you can 'load' the raster in R with raster('your_raster.tif') but it is too large to go in memory while attempting to use it with other functions. – WAF Sep 17 '14 at 10:05
3

This appears to have been a bug with the r 'raster' package version 2.2-31 released a bit before this post. I was able to work around the issue by upgrading the package to 2.3-12 which ran the exact same code without the error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.