10

I want to work with raster data in R, but I have problems exporting my raster dataset from ArcMap. By "export data"/GRID I get a file with an *.aux extension. What I need is *.grd.

Can anybody help me out?

3
  • Raster to Other Formats > help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//… GRID
    – Mapperz
    Commented Nov 9, 2011 at 15:08
  • 5
    It would help would-be respondents to know that a .grd file is in a format particular to the raster package in R. Don't expect to find (yet) any way to write this format in Arc* and beware of confusing this format with other formats that use "grd" as an extension.
    – whuber
    Commented Nov 9, 2011 at 15:58
  • What format is your original raster in? @RobertH points out that you can probably read it into R directly, without needing to export it.
    – djq
    Commented Nov 29, 2011 at 15:33

4 Answers 4

6

The answer is do not export, because there is no need to. You can directly read Arc* grid data with the raster package (when library rgdal is availabled). And if you export, it is better to avoid ascii (use e.g. GTiff).

library(raster)
library(rgdal)
#For an arc/grid (albem_s1 is the folder!):
r <- raster("G:/USGS/DEM/7_5min/VA/albem_s1")

#For a geotiff
r <- raster("G:/USGS/DEM/7_5min/VA/albem_s1.tif")
0
6

Edit

A more convenient solution for reading is provided by @RobertH elsewhere in this thread. You can read the Arc* grid dataset directly using the same approach described here: simply reference the folder in which the grid datafiles lie in the raster command.

Original reply

In Arc*, use the Raster to ASCII tool (found in Conversion Tools|From Raster) to export a grid in ASCII format.

In R, load the raster and rgdal packages, then read the raster using the raster function, as in

r <- raster("G:/USGS/DEM/7_5min/VA/albem_s1.txt")
plot(r)

To create the .grd version, use writeRaster, as in

writeRaster(r, "G:/USGS/DEM/7_5min/VA/albem_s1.grd")

The console response will describe what's in the .grd part of the output (the data are in a .gri file), as in

class       : RasterLayer 
filename    : G:/USGS/DEM/7_5min/VA/albem_s1.grd 
nrow        : 1415 
ncol        : 1133 
ncell       : 1603195 
min value   : 70 
max value   : 960 
projection  : +proj=utm +zone=17 +ellps=GRS80 +datum=NAD83 +units=m +no_defs +towgs84=0,0,0 
xmin        : 686280 
xmax        : 720270 
ymin        : 4179990 
ymax        : 4222440 
xres        : 30 
yres        : 30 
4
  • This is a very small point, but if it is exported as ascii should the file type not be *.asc? I suppose both work, but perhaps it might be a problem if you try opening a *.txt file using ArcGIS.
    – djq
    Commented Nov 29, 2011 at 15:35
  • 1
    File format and file extension are independent things, @celenius. True, some OSes and some software use the extension as a hint as to the format (although good software will either automatically override that hint or will override it at a user's request). In this example, however, the names do not matter in the least. If you do have problems importing or opening a file with a .txt extension in ArcGIS, you can always rename it, but that's not in the scope of this question.
    – whuber
    Commented Nov 29, 2011 at 15:52
  • I do appreciate the distinction between file format and file extension. I was mainly curious why one would choose to output the file as .txt rather than .asc. I thought it might be counter-intuitive.
    – djq
    Commented Nov 29, 2011 at 16:56
  • @celenius The input in this example has a .txt extension (not the output). It was taken from an actual example in which the .txt file had originally been produced by older software.
    – whuber
    Commented Apr 10, 2012 at 19:27
2

It doesn't appear that an ESRI GRID file has a single file with a .grd extension. Instead it seems to be a multi-folder/multi-file format that ArcMap sees as one file (akin to how shapefiles and ArcInfo coverages work). In any case the .aux file is a helper file to the GRID format that stores information that can't be stored in the raster itself. Here are some links that talks about it:

About auxiliary files http://webhelp.esri.com/arcgiSDEsktop/9.3/index.cfm?TopicName=About_auxiliary_files

When is an .aux file created? http://support.esri.com/en/knowledgebase/techarticles/detail/29821

3
  • 2
    people, please don't downvote without explaining why unless it's bleeding obvious what's wrong. In this case, I don't get it. ((Hi Damon, welcome to GIS.se. It gets better, honest. ;-)) Commented Nov 9, 2011 at 19:43
  • Note, @Matt, that the hovertext for the downvote button says "This answer is not useful...", not that it's wrong. The question doesn't ask what a .aux file is: it (clearly and succinctly) asks for help creating a .grd file for input to R. So it seems to me that although the advice offered in this reply is correct, it fails the usefulness test. In this respect downvotes serve future readers by steering them away from advice that may be well-meaning, correct, and even well-written and interesting, but (in the community's opinion) is likely to be fruitless.
    – whuber
    Commented Nov 9, 2011 at 21:09
  • Thanks @whuber. It helps to be reminded to look at the text of what's actually presented, and contrast it with the meaning I've built up in my head over time. There's been some continental drift! Commented Nov 9, 2011 at 21:26
1

convert your raster data to ascii and save in any of your directory. then n R

library(rgdal)
libray(sp)
data<-readGDAL("C:/filepath/file")

this will read your ascii grided file you can also chech your data by varioud commands such as

summary(data)

alernatively save your raster data as TIFF then using the same package (rgdal) it reads the tiff files you will read as

data<-readGDAL("C:/filepath/file.tiff")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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