Goal: Export a raster from R in a format that is recognized by ArcGIS.

1 File types

The file I’m working with is a .grd type file, the native raster package format usually used in R:

PEM60RAT <- raster("PEM60RAT.grd")

There are a number of different raster file types and ArcGIS can only read a few of them. Using the writeRaster function you can save a raster as a different file type.

Here is the full list of file types:

File type Long name default extension Multiband support
raster ‘Native’ raster package format .grd Yes
ascii ESRI Ascii .asc No
SAGA SAGA GIS .sdat No
IDRISI IDRISI .rst No
CDF netCDF (requires ncdf4) .nc Yes
GTiff GeoTiff (requires rgdal) .tif Yes
ENVI ENVI .hdr Labelled .envi Yes
EHdr ESRI .hdr Labelled .bil Yes
HFA Erdas Imagine Images (.img) .img Yes

1.1 Choosing a File Type

To chose which file type to save your raster as, write it out in the file name:

writeRaster(PEM60RAT, filename = "PEM60RAT.tif")

The raster will take up more or less space on your computer depending on which file type you use. The table below shows you how much space my PEM60RAT raster used when saved as each different file type:

File type File size Opens in ArcGIS Fxnl Att. table
.asc 64,731 KB Yes No
.img 44,926 KB Yes No
.tif 4,255 KB Yes No
.bil 44,256 KB Sort of No
.grd 3 KB No No
.sdat 44,256 KB No No
.rst 44,256 KB No No
.envi 44,256 KB No No

Only .asc, .img, and .tif open properly in ArcGIS. I’ve found no practical difference between them, so I would suggest using .tif because uses the least amount of space.

.bil will open in ArcGIS but doesn’t plot properly. It also will not export if you already have an .hdr file.

Although PEM60RAT has an attribute table, none of these file formats will carry the attribute table over into ArcGIS.

2 Make Raster Auxiliary files in R

ArcGIS needs auxiliary files to make an attribute table for a raster. So you need to tell R to create those aux files. The clause added to the code below tells R to make a .tfw file in addition to the .tif file:

writeRaster(PEM60RAT, filename = "PEM60RAT.tif", options=c('TFW=YES'))

Here is a list of the other auxiliary files ArcGIS likes to use to handle rasters:

File Type Purpose
tfw ESRI World file
ovr pyramid layers
xml schema look and histogram
cpg TIFF interpretation.
dbf raster attribute table

Unfortunately, I couldn’t get ArcGIS to recognize the attributes table.

3 Build a Raster Attribute Table in ArcGIS

If doing all that in R isn’t working out for you, or if you open your file in ArcGIS and it still doesn’t have an attribute table, here is how to add an attribute table onto your raster within ArcGIS.

File > Add Data > Add Data > PEM60RAT.tif

Toolbox > Data Management > Raster > Raster Dataset > Copy
Raster

Pixel type > 32\_Bit\_Signed Integer

Toolbox > data management > raster > raster properties >
build raster attribute table > PEM60RAT\_CopyRaster.

This makes a copy of your raster with signed integer pixels (rather than floating point pixels) and then builds an attribute table for that copy. This attribute table has three columns, OBJECTID, Value, and Count. This is similar to ratifying a raster in R.

We have a separate file (NS_PEM_final_attributes.csv) that contains the actual attribute table for the raster. Use the Join function to attach it to your raster:

File > Add Data > Add Data > NS\_PEM\_final\_attributes.csv > 
(right click raster copy) > Joins and Relates > Join > Join attributes from a table.

1.  Choose the field in this layer that the join will be based on: Value
2.  Choose the table to join to this layer:
    NS\_PEM\_final\_attributes.csv
3.  Choose the field in the table to base the join on: Value

This adds new columns to the raster attribute table based on the data in the NS\_PEM\_final\_attributes.csv table. Rows are matched up according to the Value column, which is present in both tables.

Next, to make the colors of the land cover types:

(right click raster copy) >Properties > Symbology > Unique
Values > Value Field > CLASS

From here you can set a color scheme or set individual colors by double clicking on the icons in the symbol column.