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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Apr 5 17:30:48 CEST 2009


Author: rhijmans
Date: 2009-04-05 17:30:47 +0200 (Sun, 05 Apr 2009)
New Revision: 393

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


Modified: pkg/raster/R/writeGDAL.R
===================================================================
--- pkg/raster/R/writeGDAL.R	2009-04-03 07:50:04 UTC (rev 392)
+++ pkg/raster/R/writeGDAL.R	2009-04-05 15:30:47 UTC (rev 393)
@@ -62,10 +62,27 @@
 	if ( rownr == 1) {
 		transient <- .getGDALtransient(raster, gdalfiletype, overwrite, mvFlag, options)
 		attr(raster at file, "transient") <- transient
-		
 #		raster at file@driver <- 'gdal'
 		raster at data@source <- 'disk'		
 	}	
+	
+#	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@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 ) 
+#	}
+	
+	if (!raster at data@haveminmax) {
+		rsd <- na.omit(raster at data@values) # min and max values
+		if (length(rsd) > 0) {
+			raster at data@min <- min(raster at data@min, min(rsd))
+			raster at data@max <- max(raster at data@max, max(rsd))
+		}	
+	}
+	
     for (band in 1:nlayers(raster)) {
 		x <- putRasterData(raster at file@transient, values(raster, rownr), band, c((rownr-1), 0)) 
 	}
@@ -76,9 +93,12 @@
 		# establish the handle:
 		rasterout <- raster(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
+		if (!raster at data@haveminmax) {
+			rasterout at data@min <- raster at data@min
+			rasterout at data@max <- raster at data@max
+		}
+		rasterout at data@haveminmax <- TRUE
+		
 		.writeStx(rasterout) 
 		return(rasterout)
 	}



More information about the Raster-commits mailing list