\HeaderA{readGDAL}{Read/write between GDAL grid maps and Spatial objects}{readGDAL}
\aliasA{writeGDAL}{readGDAL}{writeGDAL}
\keyword{spatial}{readGDAL}
\begin{Description}\relax
The functions read or write GDAL grid maps. They will set the spatial reference system if available.
\end{Description}
\begin{Usage}
\begin{verbatim} 
readGDAL(fname, offset, region.dim, ..., half.cell=c(0.5, 0.5), silent = FALSE)
writeGDAL(dataset, fname, drivername = "GTiff", type = "Float32", mvFlag = NA, options=""
)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{fname}] file name of grid map 
\item[\code{offset}] Number of rows and columns from the origin (usually the upper left corner) to begin reading from; presently ordered (y,x) - this may change
\item[\code{region.dim}] The number of rows and columns to read from the dataset; presently ordered (y,x) - this may change
\item[\code{half.cell}] Used to adjust the intra-cell offset from corner to centre, usually as default, but may be set to c=(0,0) if needed; presently ordered (y,x) - this may change
\item[\code{silent}] logical; if TRUE, comment is suppressed 
\item[\code{...}] arguments passed to either \code{getRasterData}, or
\code{getRasterTable}, depending on rotation angles (see below);
see the rgdal documentation for the available options (subsetting
etc.) 
\item[\code{dataset}] object of class \LinkA{SpatialGridDataFrame-class}{SpatialGridDataFrame.Rdash.class} or \LinkA{SpatialPixelsDataFrame-class}{SpatialPixelsDataFrame.Rdash.class}
\item[\code{drivername}] GDAL driver name 
\item[\code{type}] GDAL write data type (others than this default have not been tested) 
\item[\code{ mvFlag }] missing value flag for output file 
\item[\code{options}] driver-specific options to be passed to the GDAL driver
\end{ldescription}
\end{Arguments}
\begin{Value}
\code{read.GDAL} returns the data in the file as a Spatial object. 

Usually, GDAL maps will be north-south oriented, in which case the rgdal
function \code{getRasterData} is used to read the data, and an object
of class \LinkA{SpatialGridDataFrame-class}{SpatialGridDataFrame.Rdash.class} is returned.

Some map formats supported by GDAL are not north-south oriented grids. If
this is the case, \code{readGDAL} returns the data as a set of point
data, being of class \LinkA{SpatialPointsDataFrame-class}{SpatialPointsDataFrame.Rdash.class}. If the points
are on a 45 or 90 degree rotated grid, you can try to enforce gridding
later on by e.g. using \code{\LinkA{gridded}{gridded}(x)=TRUE}.
\end{Value}
\begin{Author}\relax
Edzer J.\ Pebesma, e.pebesma@geo.uu.nl
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{as.image.SpatialGridDataFrame}{as.image.SpatialGridDataFrame}}, \code{\LinkA{image}{image}}, \code{\LinkA{readAsciiGrid}{readAsciiGrid}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
x <- readGDAL(system.file("external/test.ag", package="sp")[1])
class(x)
image(x)
summary(x)
x@data[[1]][x@data[[1]] > 10000] <- NA
summary(x)
image(x)

x <- readGDAL(system.file("external/simple.ag", package="sp")[1])
class(x)
image(x)
summary(x)
y = readGDAL(system.file("pictures/Rlogo.jpg", package = "rgdal")[1])
summary(y)
spplot(y, zcol=1:3, names.attr=c("red","green","blue"), 
        col.regions=grey(0:100/100),
        main="example of three-layer (RGB) raster image", as.table=TRUE)
data(meuse.grid)
gridded(meuse.grid) = ~x+y
proj4string(meuse.grid) = CRS("+init=epsg:28992")
fn <- tempfile()
writeGDAL(meuse.grid["dist"], fn)
mg2 <- readGDAL(fn)
proj4string(mg2)
SP27GTIF <- readGDAL(system.file("pictures/SP27GTIF.TIF", package = "rgdal")[1])
summary(SP27GTIF)
image(SP27GTIF, col=grey(1:99/100))
cea <- readGDAL(system.file("pictures/cea.tif", package = "rgdal")[1])
summary(cea)
image(cea, col=grey(1:99/100))
erdas_spnad83 <- readGDAL(system.file("pictures/erdas_spnad83.tif", package = "rgdal")[1])
summary(erdas_spnad83)
image(erdas_spnad83, col=grey(1:99/100))
\end{ExampleCode}
\end{Examples}

