warning: Parameter 2 to gmap_gmap() expected to be a reference, value given in /home/spatiala/public_html/book/includes/module.inc on line 497.

SAGA GIS Binary Grid (.sdat) driver now available for GDAL

Roger Bivand (with the help of Volker Wichmann, Frank Warmerdam and Johan Van de Wauw) have just released the new development version of the rgdal package which now includes SAGA GIS Binary Grid (.sdat) driver. To install the packages use (the development version will soon be put on CRAN):

> download.file("http://spatial.nhh.no/R/Devel/rgdal_0.6-23.zip", destfile=paste(getwd(), "rgdal_0.6-23.zip", sep="/"))
trying URL 'http://spatial.nhh.no/R/Devel/rgdal_0.6-23.zip'
Content type 'application/zip' length 7958270 bytes (7.6 Mb)
opened URL
downloaded 7.6 Mb
> install.packages("rgdal_0.6-23.zip", repos = NULL)
package 'rgdal' successfully unpacked and MD5 sums checked
updating HTML package descriptions

then load the library in your R session:

> library(rgdal)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.7.0dev, released 2008/11/26
Path to GDAL shared files: C:/PROGRA~2/R/R-29~1.2/library/rgdal/gdal
Loaded PROJ.4 runtime: Rel. 4.6.1, 21 August 2008
Path to PROJ.4 shared files: C:/PROGRA~2/R/R-29~1.2/library/rgdal/proj
Warning message:
package 'rgdal' was built under R version 2.10.0

The short driver name is:

> getGDALDriverNames()[71,]
   name                    long_name create copy
71 SAGA SAGA GIS Binary Grid (.sdat)   TRUE TRUE

To write to SAGA grid, use:

# Load the data:
> data(meuse.grid)
> coordinates(meuse.grid) <- ~x+y
> gridded(meuse.grid) <- TRUE
> fullgrid(meuse.grid) <- TRUE

> writeGDAL(meuse.grid["dist"], "meuse_dist.sdat", drivername="SAGA")

which will create two files: (1) the header file (*.sgrd) and (2) the binary file (*.sdat). To check that everything is ok, run:

> file.show("meuse_dist.sgrd")
NAME    = meuse_dist
UNIT    =
POSITION_XMIN    = 178460.0000000000
POSITION_YMIN    = 329620.0000000000
CELLCOUNT_Y    = 104
CELLSIZE    = 40.0000000000
Z_FACTOR    = 1.000000
NODATA_VALUE    = -1.000000

To read SAGA grids to R, use:

> meuse.sgrd <- readGDAL("meuse_dist.sdat")
meuse_dist.sdat has GDAL driver SAGA
and has 104 rows and 78 columns