[Raster-commits] r327 - pkg/raster/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Mar 8 09:33:03 CET 2009


Author: rhijmans
Date: 2009-03-08 09:33:02 +0100 (Sun, 08 Mar 2009)
New Revision: 327

Modified:
   pkg/raster/R/writeGDAL.R
   pkg/raster/R/writeRaster.R
Log:


Modified: pkg/raster/R/writeGDAL.R
===================================================================
--- pkg/raster/R/writeGDAL.R	2009-03-08 08:03:14 UTC (rev 326)
+++ pkg/raster/R/writeGDAL.R	2009-03-08 08:33:02 UTC (rev 327)
@@ -87,18 +87,22 @@
 #	}
 	if ( rownr == 1) {
 		transient <- .getGDALtransient(raster, gdalfiletype, overwrite, mvFlag, options)
-		attr(raster, "transient") <- transient
+		attr(raster at file, "transient") <- transient
+		
 		raster at file@driver <- 'gdal'
 		raster at file@gdalhandle <- list()
 		raster at data@source <- 'disk'		
 	}	
     for (band in 1:nlayers(raster)) {
-		x <- putRasterData(raster at transient, values(raster, rownr), band, c((rownr-1), 0)) 
+		x <- putRasterData(raster at file@transient, values(raster, rownr), band, c((rownr-1), 0)) 
 	}
 	if ( rownr == nrow(raster)) {
-		saveDataset(raster at transient, filename(raster) )
-		GDAL.close(raster at transient) 
+		saveDataset(raster at file@transient, filename(raster) )
+		GDAL.close(raster at file@transient) 
+		
+		# establish the handle:
 		rasterout <- rasterFromFile(filename(raster))
+		
 		rasterout at data@haveminmax <- raster at data@haveminmax
 		rasterout at data@min <- raster at data@min
 		rasterout at data@max <- raster at data@max

Modified: pkg/raster/R/writeRaster.R
===================================================================
--- pkg/raster/R/writeRaster.R	2009-03-08 08:03:14 UTC (rev 326)
+++ pkg/raster/R/writeRaster.R	2009-03-08 08:33:02 UTC (rev 327)
@@ -67,7 +67,8 @@
 	} else {
 		binraster <- .setFileExtensionValues(filename(raster))
 		con <- file(binraster, "wb")
-		writeBin( values(raster), con, size = dataSize(raster at file@datanotation) ) 
+		dsize <- dataSize(raster at file@datanotation)
+		writeBin( values(raster), con, size = dsize ) 
 		close(con)
 		.writeRasterHdr(raster) 
 	}	
@@ -97,7 +98,11 @@
 	}
 	raster at file@name <- .setFileExtensionHeader(filename(raster))
 	binraster <- .setFileExtensionValues(filename(raster))
-	attr(raster, "filecon") <- file(binraster, "wb")
+	
+	attr(raster at file, "con") <- file(binraster, "wb")
+	attr(raster at file, "dsize") <- dataSize(raster at file@datanotation)
+	attr(raster at file, "dtype") <- .shortDataType(raster at file@datanotation)
+	
 	raster at data@min <- Inf
 	raster at data@max <- -Inf
 	raster at data@haveminmax <- FALSE
@@ -108,7 +113,7 @@
 
 .stopRowWriting <- function(raster) {
 	.writeRasterHdr(raster) 
-	close(raster at filecon)
+	close(raster at file@con)
 	raster at data@haveminmax <- TRUE
 	raster at data@source <- 'disk'
 	raster at data@content <- 'nodata'
@@ -121,19 +126,19 @@
 #	if (dataContent(raster) != 'row') { 
 #		stop('raster does not contain a row') 
 #	}
+
+	if (dataIndices(raster)[1] == 1) { 
+		raster <- .startRowWriting(raster, overwrite=overwrite)
+ 	} 
+
 	raster at data@values[is.nan(raster at data@values)] <- NA
 	raster at data@values[is.infinite(raster at data@values)] <- NA
-	
-	dtype <- .shortDataType(raster at file@datanotation)
-	if (dtype == "integer" |  dtype =='logical' ) { 
+	if (raster at file@dtype == "INT" || raster at file@dtype =='LOG' ) { 
 		values <- as.integer(round(raster at data@values))  
 		values[is.na(values)] <- as.integer(raster at file@nodatavalue)		
 	} else { 
-		values  <- as.numeric(raster at data@values) 
+		values  <- as.numeric( raster at data@values ) 
 	}
-	if (dataIndices(raster)[1] == 1) { 
-		raster <- .startRowWriting(raster, overwrite=overwrite)
- 	} 
 	
 	rsd <- na.omit(raster at data@values) # min and max values
 	if (length(rsd) > 0) {
@@ -141,7 +146,7 @@
 		raster at data@max <- max(raster at data@max, max(rsd))
 	}	
 	
-	writeBin(values, raster at filecon, size = dataSize(raster at file@datanotation) )
+	writeBin(values, raster at file@con, size = raster at file@dsize )
 	
 	if (dataIndices(raster)[2] >= ncell(raster)) {
 		raster <- .stopRowWriting(raster)



More information about the Raster-commits mailing list