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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jan 27 09:08:18 CET 2009


Author: rhijmans
Date: 2009-01-27 09:08:18 +0100 (Tue, 27 Jan 2009)
New Revision: 191

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


Modified: pkg/raster/R/set.R
===================================================================
--- pkg/raster/R/set.R	2009-01-27 07:27:51 UTC (rev 190)
+++ pkg/raster/R/set.R	2009-01-27 08:08:18 UTC (rev 191)
@@ -142,8 +142,8 @@
 		}
 	}
 #	if (raster at file@datatype == 'logical') {
-#		raster at data@min <- as.logical(min(raster at data@min))
-#		raster at data@max <- as.logical(max(raster at data@max))
+#		raster at data@min <- as.logical(raster at data@min)
+#		raster at data@max <- as.logical(raster at data@max)
 #	}
 	raster at data@haveminmax <- TRUE
 	return(raster)

Modified: pkg/raster/R/writeRaster.R
===================================================================
--- pkg/raster/R/writeRaster.R	2009-01-27 07:27:51 UTC (rev 190)
+++ pkg/raster/R/writeRaster.R	2009-01-27 08:08:18 UTC (rev 191)
@@ -58,14 +58,11 @@
 		}	
 	}
 
-
-
 	if (raster at data@content == 'sparse') { 
 		raster <- .writeSparse(raster, overwrite=overwrite) 
 	} else {
 		binraster <- .setFileExtensionValues(filename(raster))
 		con <- file(binraster, "wb")
-		print(raster at file@datasize)
 		writeBin( values(raster), con, size = raster at file@datasize) 
 		close(con)
 		.writeRasterHdr(raster) 
@@ -73,6 +70,7 @@
 	
 	# put logical values back to T/F
 	if ( raster at file@datatype =='logical') {
+		raster at data@values[raster at data@values <=  raster at file@nodatavalue]  <- NA
 		raster at data@values <- as.logical(values(raster))
 	}
 	
@@ -110,32 +108,26 @@
  
  
 .writeRasterRow <- function(raster, overwrite=FALSE) {
-	if (dataContent(raster) != 'row') { 
-		stop('raster does not contain a row') 
-	}
+#	if (dataContent(raster) != 'row') { 
+#		stop('raster does not contain a row') 
+#	}
 	
-	
-	if (raster at file@datatype == "integer") { 
-		raster at data@values <- as.integer(round(raster at data@values))  
+	raster at data@values[is.nan(raster at data@values)] <- NA
+	raster at data@values[is.infinite(raster at data@values)] <- NA
+
+	if (raster at file@datatype == "integer" |  raster at file@datatype =='logical' ) { 
+		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) 
 	}
-	if (class(values(raster)) == "integer" & raster at file@datatype == "numeric") { 
-		raster at data@values  <- as.numeric(values(raster)) 
-	}
-	if ( raster at file@datatype =='logical') {
-	# values should be written as 0 / 1 ( integers)
-		raster at data@values <- as.integer(values(raster))
-	}
-		
-	
+
 	if (dataIndices(raster)[1] == 1) { 
 		raster <- ..startWriting(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
+	writeBin(values, raster at filecon, size = raster at file@datasize)
 	
-	writeBin(raster at data@values, raster at filecon, size = raster at file@datasize)
-	
 	if (dataIndices(raster)[2] >= ncell(raster)) {
 		raster <- ..stopWriting(raster)
 		if (dataIndices(raster)[2] > ncell(raster)) {



More information about the Raster-commits mailing list