Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i want to export a grid from R into format readable by ArcGIS. how can i do so?

share|improve this question

migrated from Dec 5 '12 at 13:43

This question came from our site for professional and enthusiast programmers.

You need to specify what the target software can read, or at least what version of it you are using so someone can find out. Recent versions of ArcGIS use GDAL so rgdal is the best place to start. GeoTIFF is generally the best choice unless you have special needs – mdsumner Dec 5 '12 at 12:46
The target software is ArcGIS 10. I just wanted an output of the formart a ascii with some header information on x and y coordinates, NA, ncol and nrow. – jonestats Dec 5 '12 at 13:31
In the future, when posting, please consider providing more specifics so the community can provide relevant answers without the need for you to clarify you question. Your reference to "grid" in R is vague at best and could be interpreted as a matrix class, raster class or sp class object. Since some spatial packages in R return a matrix you may need to coerce to a raster object before export to an ASCIIGrid is feasible. For all we know you wanted to end up with an X,Y,Z triplicate. – Jeffrey Evans Dec 5 '12 at 17:41
FWIW raster, sp, and rgdal all provide independent support to create ESRI Ascii files, but it's a very poor choice given the lack of projection metadata, tiling, or compression and inconsistent support for non-square cells – mdsumner Dec 5 '12 at 19:28

The raster package has functions to read and write GRID files.

Other packages for working with spatial data and interacting with GIS software can be found in the spatial task view on CRAN:

share|improve this answer
Thanks, i found the package RSAGA useful and i have solved the issue. – jonestats Dec 5 '12 at 13:05
+1 raster package – Aaron Dec 5 '12 at 14:22
There is also the rgdal package. I am not sure how RSAGA would solve your export problem. The data engine behind SAGA is GDAL so using the rgdal package would allow you to export a raster info any number of formats readable by ArcGIS, including ascii grid. I would however, recommend img. – Jeffrey Evans Dec 5 '12 at 17:33

To expand on @Chris's answer, use raster::writeRaster to write to any of a large variety of raster formats. Depending on whether your build of GDAL, you should be able to write to these (and possibly more) filetypes (returned by raster::writeFormats()):

#         name                               long_name
# 1     raster                                R-raster
# 2       SAGA                                SAGA GIS
# 3     IDRISI                                  IDRISI
# 4  IDRISIold                        IDRISI (img/doc)
# 5        BIL                            Band by Line
# 6        BSQ                         Band Sequential
# 7        BIP                           Band by Pixel
# 8      ascii                               Arc ASCII
# 9        CDF                                  NetCDF
# 10       big                              big.matrix
# 11      ADRG           ARC Digitized Raster Graphics
# 12       BMP    MS Windows Device Independent Bitmap
# 13        BT     VTP .bt (Binary Terrain) 1.3 Format
# 14   CTable2                CTable2 Datum Grid Shift
# 15      EHdr                      ESRI .hdr Labelled
# 16      ELAS                                    ELAS
# 17      ENVI                      ENVI .hdr Labelled
# 18       ERS                  ERMapper .ers Labelled
# 19     GS7BG    Golden Software 7 Binary Grid (.grd)
# 20      GSBG      Golden Software Binary Grid (.grd)
# 21     GTiff                                 GeoTIFF
# 22       GTX                NOAA Vertical Datum .GTX
# 23       HFA             Erdas Imagine Images (.img)
# 24       IDA                 Image Data and Analysis
# 25     ILWIS                        ILWIS Raster Map
# 26      INGR                       Intergraph Raster
# 27     ISIS2 USGS Astrogeology ISIS cube (Version 2)
# 28       KRO                               KOLOR Raw
# 29       LAN                         Erdas .LAN/.GIS
# 30  Leveller                    Leveller heightfield
# 31      NITF    National Imagery Transmission Format
# 32      NTv2                   NTv2 Datum Grid Shift
# 33      PAux                       PCI .aux Labelled
# 34    PCIDSK                    PCIDSK Database File
# 35       PNM         Portable Pixmap Format (netpbm)
# 36       RMF                    Raster Matrix Format
# 37       RST                       Idrisi Raster A.1
# 38      SAGA            SAGA GIS Binary Grid (.sdat)
# 39       SGI               SGI Image File Format 1.0
# 40  Terragen                    Terragen heightfield

For example:

r <- raster(matrix(runif(100), 10))
writeRaster(r, 'example.tif')

Note that if your data are held in a matrix, you should create a raster object first, as I've done above.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.