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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Mar 20 09:19:16 CET 2009


Author: rhijmans
Date: 2009-03-20 09:19:16 +0100 (Fri, 20 Mar 2009)
New Revision: 376

Modified:
   pkg/raster/R/hist.R
   pkg/raster/R/properties.R
   pkg/raster/R/readCells.R
   pkg/raster/R/readRaster.R
   pkg/raster/R/replacement2.R
   pkg/raster/R/singleIndex.R
Log:


Modified: pkg/raster/R/hist.R
===================================================================
--- pkg/raster/R/hist.R	2009-03-19 12:28:50 UTC (rev 375)
+++ pkg/raster/R/hist.R	2009-03-20 08:19:16 UTC (rev 376)
@@ -7,7 +7,7 @@
 setMethod('hist', signature(x='RasterStack'), 
 	function(x, layer=1, maxsamp=10000, ...) {
 		x <- asRasterLayer(x, layer)
-		callNextMethod(x, maxsamp=10000, ...)
+		hist(x, maxsamp=10000, ...)
 	}
 )
 

Modified: pkg/raster/R/properties.R
===================================================================
--- pkg/raster/R/properties.R	2009-03-19 12:28:50 UTC (rev 375)
+++ pkg/raster/R/properties.R	2009-03-20 08:19:16 UTC (rev 376)
@@ -44,8 +44,10 @@
 .driver <- function(object) {
 	if (class(object at file@con)[1] == 'file') {
 		return('raster')
-	} else { #  if (class(object at file@con)[1] == "GDALReadOnlyDataset")
+	} else if (class(object at file@con)[1] == "GDALReadOnlyDataset") {
 		return('gdal')
+	} else {
+		stop('could not determine driver')
 	}
 }	
 

Modified: pkg/raster/R/readCells.R
===================================================================
--- pkg/raster/R/readCells.R	2009-03-19 12:28:50 UTC (rev 375)
+++ pkg/raster/R/readCells.R	2009-03-20 08:19:16 UTC (rev 376)
@@ -56,33 +56,20 @@
 }	
 
 
-
 .readCellsRaster <- function(raster, cells) {
-#	cells <- cbind(cells, NA)
-#	valuename <- raster at file@shortname
-#	if (valuename == "") {valuename <- "value" }
-#	colnames(cells) <- c("id", "cell", valuename)
-#	uniquecells <- na.omit(unique(cells[order(cells[,2]),2]))
-	
-	rastergri <- .setFileExtensionValues(filename(raster))
-	if (!file.exists(filename(raster))) { stop(paste(filename(raster)," does not exist")) }
-
-	con <- file(rastergri, "rb")
-
 	res <- vector(length=length(cells))
 	res[] <- NA
 	dsize <- dataSize(raster at file@datanotation)
-	dtype <- .shortDataType(raster at file@datanotation)
+	if (.shortDataType(raster at file@datanotation) == "FLT") { 
+		dtype <- "numeric"
+	} else { 
+		dtype <- "integer"
+	}
 	for (i in 1:length(cells)) {
-		seek(con, (cells[i]-1) * dsize)
-		if (dtype == "FLT") { 
-			dtype <- "numeric"
-		} else { 
-			dtype <- "integer"
-		}
-		res[i] <- readBin(con, what=dtype, n=1, size=dsize, endian=raster at file@byteorder) 
+		seek(raster at file@con, (cells[i]-1) * dsize)
+		res[i] <- readBin(raster at file@con, what=dtype, n=1, size=dsize, endian=raster at file@byteorder) 
 	}
-	close(con)
+	seek(raster at file@con, 0)
 	res[res <=  max(-3e+38, .nodatavalue(raster))] <- NA
 	return(cbind(cells,res))
 }

Modified: pkg/raster/R/readRaster.R
===================================================================
--- pkg/raster/R/readRaster.R	2009-03-19 12:28:50 UTC (rev 375)
+++ pkg/raster/R/readRaster.R	2009-03-20 08:19:16 UTC (rev 376)
@@ -46,6 +46,7 @@
 			seek(raster at file@con, ((rownr-1) * ncol(raster) + (startcol-1)) * dsize)
 			result <- readBin(raster at file@con, what=dtype, n=ncolumns, dsize, dsign, endian=raster at file@byteorder) }	
 		else {	
+			seek(raster at file@con, 0)
 			result <- readBin(raster at file@con, what=dtype, n=ncell(raster), dsize, dsign, endian=raster at file@byteorder) 
 		}
 #		close(con)

Modified: pkg/raster/R/replacement2.R
===================================================================
--- pkg/raster/R/replacement2.R	2009-03-19 12:28:50 UTC (rev 375)
+++ pkg/raster/R/replacement2.R	2009-03-20 08:19:16 UTC (rev 376)
@@ -26,7 +26,6 @@
 	if (dataContent(x) == 'all') {
 		m <- matrix(values(x), nrow(x), ncol(x), byrow=TRUE)
 		rm(x)
-#		callNextMethod(m, i=i, j=j, drop=drop)
 		return(m[i=i, j=j, drop=drop])
 	} else {
 		if ( missing(j) ) {

Modified: pkg/raster/R/singleIndex.R
===================================================================
--- pkg/raster/R/singleIndex.R	2009-03-19 12:28:50 UTC (rev 375)
+++ pkg/raster/R/singleIndex.R	2009-03-20 08:19:16 UTC (rev 376)
@@ -23,11 +23,12 @@
 	}
 	
 	if (dataContent(x) == 'all') {
-		callNextMethod(values(x), i=i, drop=drop )
+		values(x)[i, drop=drop]
 	} else {
 		if (missing(i)) {
 			stop('raster too large.')
 		} else {
+			print('hello')
 			return(cellValues(x, i))
 		}
 	}



More information about the Raster-commits mailing list