[Raster-commits] r166 - in pkg/raster: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jan 21 03:21:28 CET 2009


Author: rhijmans
Date: 2009-01-21 03:21:28 +0100 (Wed, 21 Jan 2009)
New Revision: 166

Modified:
   pkg/raster/DESCRIPTION
   pkg/raster/R/export.R
   pkg/raster/R/writeGDAL.R
   pkg/raster/R/writeRaster.R
   pkg/raster/man/properties.Rd
   pkg/raster/man/write.Rd
Log:


Modified: pkg/raster/DESCRIPTION
===================================================================
--- pkg/raster/DESCRIPTION	2009-01-21 01:04:50 UTC (rev 165)
+++ pkg/raster/DESCRIPTION	2009-01-21 02:21:28 UTC (rev 166)
@@ -1,8 +1,8 @@
 Package: raster
 Type: Package
 Title: Raster data handling for geographic data analysis and modeling
-Version: 0.8.6-2
-Date: 20-Jan-2009
+Version: 0.8.6-3
+Date: 21-Jan-2009
 Depends: methods, sp, rgdal (>= 0.5-33), R (>= 2.8.0)
 Author: Robert J. Hijmans & Jacob van Etten
 Maintainer: Robert J. Hijmans <r.hijmans at gmail.com> 

Modified: pkg/raster/R/export.R
===================================================================
--- pkg/raster/R/export.R	2009-01-21 01:04:50 UTC (rev 165)
+++ pkg/raster/R/export.R	2009-01-21 02:21:28 UTC (rev 166)
@@ -38,16 +38,9 @@
 	} else if (filetype == "bil") {
 		.exportToBil(raster, filename=filename, keepGRD=keepGRD, overwrite=overwrite) 
 
-	} else if (filetype == "tif") {
-		if (dataContent(raster) != "all") {
-			raster <- readAll(raster)
-		}
-		spgrid <- asSpGrid(raster)	
-		filename <- setFileExtension(filename, ".tif")
-		writeGDAL(spgrid, filename)
 
 	} else {
-		stop("filetype not yet supported (sorry..., more coming ...)")
+		stop("filetype not supported")
 	}
 	
 	return(rasterFromFile(filename))

Modified: pkg/raster/R/writeGDAL.R
===================================================================
--- pkg/raster/R/writeGDAL.R	2009-01-21 01:04:50 UTC (rev 165)
+++ pkg/raster/R/writeGDAL.R	2009-01-21 02:21:28 UTC (rev 166)
@@ -10,16 +10,9 @@
 # based on  create2GDAL and saveDataset from the rgdal package
 # authors: Timothy H. Keitt, Roger Bivand, Edzer Pebesma, Barry Rowlingson
 
-.isSupportedGDALdriver <- function(dname) {
-	gdrivers <- c("ADRG", "BMP", "BT", "EHdr", "ELAS", "ENVI", "ERS", "GSBG", "GTiff", "HFA", "IDA", "ILWIS", "INGR", "Leveller", "MEM", "MFF", "MFF2", "NITF", "PAux", "PCIDSK", "PNM", "RMF", "RST", "SGI", "Terragen", "VRT")
-	res <- dname %in% gdrivers
-	if (!res) { stop(paste(dname,"is not a supported GDAL file format. Choose from: \n    ADRG, BMP, BT, EHdr, ELAS, ENVI, ERS, GSBG, GTiff, HFA, IDA, ILWIS,\n    INGR, Leveller, MEM, MFF, MFF2, NITF, PAux, PCIDSK, PNM, RMF, RST, SGI, Terragen, VRT" ) ) }
-	return(res)
-}
 
-
 .getGDALtransient <- function(raster, gdalfiletype, overwrite, ForceIntOutput, mvFlag,  options)  {
-	.isSupportedGDALdriver(gdalfiletype)
+#	.isSupportedFormat(gdalfiletype)
 	
 # this is a RasterLayer hence nbands = 1:
     nbands = nlayers(raster)
@@ -162,6 +155,12 @@
 }
 
 
+# ALTERNATIVE
+#.writeGDALall <- function(raster, gdalfiletype, overwrite, ForceIntOutput, mvFlag, options) {
+#	spgrid <- asSpGrid(raster)	
+#	writeGDAL(spgrid, filename(raster))
+#}
+
 .writeGDALall <- function(raster, gdalfiletype, overwrite, ForceIntOutput, mvFlag, options) {
 	
 	transient <- .getGDALtransient(raster, gdalfiletype, overwrite, ForceIntOutput, mvFlag, options)

Modified: pkg/raster/R/writeRaster.R
===================================================================
--- pkg/raster/R/writeRaster.R	2009-01-21 01:04:50 UTC (rev 165)
+++ pkg/raster/R/writeRaster.R	2009-01-21 02:21:28 UTC (rev 166)
@@ -6,18 +6,29 @@
 
 
  
-.setFileExtensionValues <- function(fname) {
-	fname <- setFileExtension(fname, ".gri")
-	return(fname)
+rasterFormats <- function() {
+	gd <- gdalDrivers()
+	gd <- as.matrix(subset(gd, gd[,3] == T))
+	short <- c("raster", "ascii", as.vector(gd[,1]))
+	long <- c("raster package format", "Arc ascii", as.vector(gd[,2]))
+	m <- cbind(short, long)
+	colnames(m) <- c("name", "long_name")
+	return(m)
 }
- 
-.setFileExtensionHeader <- function(fname) {
-	fname <- setFileExtension(fname, ".grd")
-	return(fname)
+
+
+.isSupportedGDALFormat <- function(dname) {
+	gd <- gdalDrivers()
+	gd <- as.matrix(subset(gd, gd[,3] == T))
+	res <- dname %in% gd
+	if (!res) { stop(paste(dname, "is not a supported file format. See rasterFormats()" ) ) }
+	return(res)
 }
+
  
  
 writeRaster <- function(raster, format='raster', overwrite=FALSE) {
+	
 	if (dataContent(raster) != 'row' & dataContent(raster) != 'all' & dataContent(raster) != 'sparse' ) {
 		stop('First use setValues()')
 	}
@@ -30,14 +41,12 @@
 		}  
 	} else if (format=='ascii') {
 		raster <- .writeAscii(raster, overwrite)
-	} else {
-		mvFlag = NA
-		options = NULL
-		ForceIntOutput = FALSE
+	} else { 
+		.isSupportedGDALFormat(format)
 		if (dataContent(raster) == 'row' ) {
-			raster <- .writeGDALrow(raster, format, overwrite, ForceIntOutput, mvFlag, options)
+			raster <- .writeGDALrow(raster, format, overwrite, ForceIntOutput=FALSE, mvFlag=NA, options=NULL)
 		} else {
-			raster <- .writeGDALall(raster, format, overwrite, ForceIntOutput, mvFlag, options)
+			raster <- .writeGDALall(raster, format, overwrite, ForceIntOutput=FALSE, mvFlag=NA, options=NULL)
 		}  
 	}
 	return(raster)
@@ -46,6 +55,18 @@
 
 
 
+
+.setFileExtensionValues <- function(fname) {
+	fname <- setFileExtension(fname, ".gri")
+	return(fname)
+}
+ 
+.setFileExtensionHeader <- function(fname) {
+	fname <- setFileExtension(fname, ".grd")
+	return(fname)
+}
+ 
+
 .writeRasterAll <- function(raster, overwrite=FALSE) {
 	raster <- setFilename(raster, .setFileExtensionHeader(filename(raster)))
 	if (filename(raster) == "") {

Modified: pkg/raster/man/properties.Rd
===================================================================
--- pkg/raster/man/properties.Rd	2009-01-21 01:04:50 UTC (rev 165)
+++ pkg/raster/man/properties.Rd	2009-01-21 02:21:28 UTC (rev 166)
@@ -22,6 +22,7 @@
 \alias{projection<-}
 \alias{origin}
 \alias{nlayers}
+\alias{nlayers,BasicRaster-method}
 \alias{nlayers,Raster-method}
 \alias{nlayers,RasterBrick-method}
 \alias{nlayers,RasterStack-method}

Modified: pkg/raster/man/write.Rd
===================================================================
--- pkg/raster/man/write.Rd	2009-01-21 01:04:50 UTC (rev 165)
+++ pkg/raster/man/write.Rd	2009-01-21 02:21:28 UTC (rev 166)
@@ -1,6 +1,7 @@
 \name{write}
 
 \alias{writeRaster}
+\alias{rasterFormats}
 
 \title{Write raster data to a file}
 
@@ -11,6 +12,7 @@
 
 \usage{
   writeRaster(raster, format='raster', overwrite=FALSE)
+  rasterFormats()
 }
 
 \arguments{
@@ -23,42 +25,21 @@
 	Values in a \code{RasterLayer} object are written to a file. Relatively small datasets can be loaded into memory, manipulated, and saved to disk in their entirety. 
 	Large datasets can be read and written row by row. 
 	When writing by row, you must write all rows, and you must write them in sequence. Start at row=1, and end at row=nrow(raster). You cannot overwrite a single row in an existing raster file.
-	
+	rasterFormats returns a matrix of the file formats (the "drivers") that are supported.
 
-Supported GDAL drivers are:
-	\item{Driver}{Long name}
-	\item{ADRG}{ARC Digitized Raster Graphics}
-	\item{BMP}{MS Windows Device Independent Bitmap}
-	\item{BT}{VTP .bt (Binary Terrain) 1.3 Format}
+Supported formats include 
+	\item{Format}{Long name}
+	\item{raster}{'Native' raster package format}
+	\item{ascii}{Arc Ascii format}
+	\item{ENVI}{ENVI .hdr Labelled}
 	\item{EHdr}{ESRI .hdr Labelled}
-
-	ESRI .hdr Labelled
-	ELAS			ELAS
-	
-	ENVI			ENVI .hdr Labelled
-	
-	ERS				ERMapper .ers Labelled
-	
-	GSBG			Golden Software Binary Grid (.grd)
-	
-	GTiff  - GeoTiff
-	HFA    - Erdas Imagine Images (.img)
-	IDA				Image Data and Analysis
-	ILWIS			ILWIS Raster Map
-	INGR			Intergraph Raster
-	Leveller		Leveller heightfield
-	MEM				In Memory Raster
-	MFF				Vexcel MFF Raster
-	MFF2			Vexcel MFF2 (HKV) Raster
-	NITF			National Imagery Transmission Format
-	PAux			PCI .aux Labelled
-	PCIDSK			PCIDSK Database File
-	PNM				Portable Pixmap Format (netpbm)
-	RMF				Raster Matrix Format
-	RST				Idrisi Raster A.1
-	SGI				SGI	Image File Format 1.0
-	Terragen		Terragen heightfield
-	VRT				Virtual	Raster
+	\item{ERS}{ERMapper .ers Labelled}
+	\item{GTiff}{GeoTiff}
+	\item{HFA}{Erdas Imagine Images (.img)}
+	\item{ILWIS}{ILWIS Raster Map}
+	\item{PAux}{PCI .aux Labelled}
+	\item{PCIDSK}{PCIDSK Database File}
+	\item{RST}{Idrisi Raster A.1}
 }
 
 \author{Robert J. Hijmans \email{r.hijmans at gmail.com}}



More information about the Raster-commits mailing list