Geoscience Reference
In-Depth Information
stack or raster brick are held in memory, much larger data sets may be handled. The raster and
raster brick objects access single external files per object, while raster stack objects may use many
external files per object. The package also provides ways of undertaking map algebra on rasters,
including focal operations. It uses the rgdal package, among other data feeds, for reading from and
writing to files; we turn to this package next.
14.4.2 g eoSPatial d ata a BStraction l iBrary (gdal/ogr) and Proj.4: rgdal
The first raster versions of the rgdal package by Tim Keitt were made available in early 2003 and
entered CRAN in late 2003 (Keitt et al. 2011); it provided bindings to the GDAL geospatial library
for reading, writing and handling raster data. Since then, it has been merged with work on coordi-
nate reference system projection and OGR vector reading by Barry Rowlingson, extended to write
OGR vector files and supplied with wrapper functions using sp classes to contain the data being
imported and exported. Coordinate reference system projection was handled by building against
the PROJ.4 library, not least because GDAL itself requires the same library. Because rgdal loads
GDAL into a long-running application, R , the GDAL error handler is now set to the R error handler
immediately before each call to a GDAL function and restored immediately on function exit to
try to ensure thread safety, because of a report of error handler confusion when R and rgdal were
loaded into QGIS as a Python plug-in. When component stacking reaches these levels of complex-
ity, caution is required, because the developers of the components involved are unlikely to be fully
aware of each others' intentions.
Since R 2.2, a Windows 32-bit binary of rgdal has been available from CRAN, thanks to help
from Brian Ripley and Uwe Ligges, and since R 2.12 a Windows 64-bit binary version has also
been made available. These are statically linked to GDAL, PROJ.4 and Expat,* an open-source
XML library used for reading KML and GPX files. Brian Ripley and Simon Urbanek have made it
possible for CRAN to provide OS X binary packages since R 2.15; OS X binary packages are also
available from Kyngchaos, thanks to William Kyngesburye. The drivers available in the binary
packages are limited to those for which external dependencies were satisfied when the installed
images were made but meet most users' needs for file import and export.
The use of the package is covered in Bivand et al. (2008, pp. 89-97) and exemplified throughout
the code examples from the topic. Using the 8 county New York State leukaemia data set from
Waller and Gotway (2004), we can download and unzip it to a temporary directory, before reading
with readOGR :
> td <- tempdir()
> download.file("http://www.asdar-book.org/datasets/NY_data.zip",
+ destfile = paste(td, "NY_data.zip", sep = "/"))
> unzip(paste(td, "NY_data.zip", sep = "/"), exdir = td)
> library(rgdal)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.9.0, released 2011/12/29
Path to GDAL shared files:
Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
Path to PROJ.4 shared files:
> NY <- readOGR(dsn = td, layer = "NY8_utm18")
OGR data source with driver: ESRI Shapefile
Source: "/tmp/Rtmp7cVkp2", layer: "NY8_utm18"
* http://expat.sourceforge.net/.
http://www.kyngchaos.com/software/frameworks.
Search WWH ::




Custom Search