I am new in GIS, and I downloaded a gridded dataset from this source
The data come with a raster file as well as a range of attribute data files. In ArcGIS I can easily join the .mdb Microsoft Access attribute table with the .adf raster. However, I am now in a Mac, that can't handle .mdb. Fortunately the data is also downloadable in an interchangeable format, including a .tiff raster file together with several .txt files with attributes.
How can I link the TIFF with the TXT data in R or QGIS from a Mac?
Once uploaded, how can I select one particular attribute (and discard the others) similar to what I would do with the lookup
function? The idea is to finally save a raster in tiff with only one specific column among all the different variables included in the attribute tables.
Best Answer
The data appears to be in three formats: a .mdb in ./Data/, a .tif and some txt files in ./Interchangeable_format/, and an Arc/Info binary coverage in ./GISfiles with a raster layer called
wise30sec_fin
.Both the tif and the Arc/Info coverage can be read by R or QGIS via the underlying GDAL library. The tif appears to be just integers that will need to be used for lookups, but the Arc/Info coverage includes those and is a bit richer too, so I'll use that...
Use the
raster
package to read it in:Note this hasn't actually read it into memory because of its size. R will get bits of it as needed, and we have to be careful not to read it all into memory unless we have a lot of memory. You may struggle to process the whole raster in R, so crop it to your study area if you have one.
Note the raster is a single band, and has a set of attributes. This is a data frame that links integer values in the raster to attribute values. Lets look at the first few, by using
levels
on the raster. The raster is a single band, so we get the first attribute table by extracting with[[1]]
:So to get the information for a location, get the value of the raster at that location and that's the ID in the attributes table:
Now I can read in one of the data files and look up in that with the NEWSUID code:
The data is one row shorter then the attribute table, so its possible one NEWSUID code is missing:
and its the empty string which I guess is code for the sea.
Anyway, we can now select the values from the data file since we know the NEWSUID value at
r[5000,7000]
:So that's the fundamentals of looking up data values given the raster and some data. You can do all sorts of clever things like adding the data to the
levels(r)
but I think the best thing to do might depend on what you actually want to end up doing with the data - if its just sampling at a few points you might want to do something different to if you want to create a whole load of global maps of a quantity in the data files.There's a useful answer on manipulating raster level attributes here:
https://stackoverflow.com/questions/28617678/using-a-raster-attribute-from-a-multi-attribute-raster-for-colour-levels-in-a-pl
but watch out - some of those things might try and load the whole raster into memory and that might be pretty slow or hang your computer.
Alternatively, using exclusively the files in ./Interchange_files, the
tif
file stores pixel values, which are in the .tsv file, where you can lookup NEWSUID values to look up in the data file. Again, the large size stops me wanting to do this for the whole raster but everything is well-named.