Problem importing USDA Crop Data Layer (GTIFF) in

2019-07-04 21:58发布

问题:

I've downloaded the USDA Crop Data Layer (data available here, note large file: http://www.nass.usda.gov/research/Cropland/SARS1a.htm) and want to import it into R for analysis. I've imported other large GTIFF files (e.g., LANDSAT data), but get the following error when I call the function:

r <- raster(file)

Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer",  :
    Cannot create a RasterLayer object from this file.

where "file" is any of the .tif files provided by USDA (I'm using the Midwest regional compilation).

I suspect the problem is that the GTiff is categorical data (land use categories) rather than true ordinal / spectral data, but I don't understand why it would render fine in an image editor (e.g., Preview) and balk in R / GDAL.

Thanks for the help.

Edit: if this should go on the GIS forum, please let me know. Generally, it seems that programming approaches to spatial problems reside here, no?

回答1:

Hmm, renaming the file "temp.tif" or something similar solved the problem. Very odd as the filename included just a-z, 0-9, and the _ character.

To others experiencing GDAL problems: recommend playing with this. If anybody knows the true root problem, please let me know. Original filename was cdl_tim_r_ia_2010_utm15.tif, cdl_tm_r_il_2010_utm16.tif, etc.

Thanks.



回答2:

I was able to recreate your error message with the same file, and it seems that GDAL requires pathnames that go deeper than just the home directory, at least on a Mac. That is, the pathname required going back to /Users/myname/cdl_tm_r_nv_2010_utm11.tif instead of just ~/cdl_tm_r_nv_2010_utm11.tif as one of your USDA crop file examples. I managed to open the file with

library(raster)
r <- raster(file.choose())

and then just navigating to the GeoTiff.