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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Mar 19 09:54:11 CET 2009


Author: rhijmans
Date: 2009-03-19 09:54:11 +0100 (Thu, 19 Mar 2009)
New Revision: 373

Modified:
   pkg/raster/DESCRIPTION
   pkg/raster/R/Compare_Logical.R
   pkg/raster/R/Math.R
   pkg/raster/R/Merge.R
   pkg/raster/R/aggregate.R
   pkg/raster/R/calc.R
   pkg/raster/R/calcStack.R
   pkg/raster/R/copyRaster.R
   pkg/raster/R/cover.R
   pkg/raster/R/depracated.R
   pkg/raster/R/disaggregate.R
   pkg/raster/R/init.R
   pkg/raster/R/linesToRaster.R
   pkg/raster/R/neighborhood.R
   pkg/raster/R/overlayList.R
   pkg/raster/R/pointsToRaster.R
   pkg/raster/R/polygonToRaster.R
   pkg/raster/R/project.R
   pkg/raster/R/rasterFromFile.R
   pkg/raster/R/rasterFromFileGDAL.R
   pkg/raster/R/reclass.R
   pkg/raster/R/replaceProperties.R
   pkg/raster/R/resample.R
   pkg/raster/R/setDatatype.R
   pkg/raster/R/writeRaster.R
   pkg/raster/R/writeRasterSparse.R
   pkg/raster/man/setDatatype.Rd
   pkg/raster/man/writeRaster.Rd
Log:


Modified: pkg/raster/DESCRIPTION
===================================================================
--- pkg/raster/DESCRIPTION	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/DESCRIPTION	2009-03-19 08:54:11 UTC (rev 373)
@@ -1,8 +1,8 @@
 Package: raster
 Type: Package
 Title: Raster data handling for geographic data analysis and modeling
-Version: 0.8.9-7
-Date: 14-March-2009
+Version: 0.8.9-8
+Date: 19-March-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/Compare_Logical.R
===================================================================
--- pkg/raster/R/Compare_Logical.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/Compare_Logical.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -64,7 +64,7 @@
 			stop('second argument should be a single number')
 		}
 		rst <- raster(e1)
-		rst <- setDatatype(rst, 'LOG1S')
+		dataType(rst) <- 'LOG1S'
 		if (canProcessInMemory(e1, 3)) {
 			rst <- setValues(rst, values=callGeneric(.getRasterValues(e1), rep(e2, ncell(e1)) ) )			
 		} else {
@@ -132,7 +132,7 @@
     function(e1, e2){ 
 		if ( compare(c(e1, e2)) ) {
 			rst <- raster(e1)
-			rst <- setDatatype(rst, 'LOG1S')
+			dataType(rst) <- 'LOG1S'
 			if (canProcessInMemory(e1, 3)) {
 				rst <- setValues(rst, callGeneric(.getLogicalValues(e1), .getLogicalValues(e2)))
 			} else {

Modified: pkg/raster/R/Math.R
===================================================================
--- pkg/raster/R/Math.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/Math.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -13,12 +13,12 @@
 		if (canProcessInMemory(x, 3)) {
 			rst <- raster(x, values=callGeneric(.getRasterValues(x)))
 			if (fname %in% c('floor', 'ceiling', 'trunc')) {
-				rst <- setDatatype(rst, 'INT4S')
+				dataType(rst) <- 'INT4S'
 			}
 		} else {
 			rst <- raster(x, filename=tempfile())
 			if (fname %in% c('floor', 'ceiling', 'trunc')) {
-				rst <- setDatatype(rst, 'INT4S')
+				dataType(rst) <- 'INT4S'
 			}
 			for (r in 1:nrow(x)) {
 				rst <- setValues(rst, callGeneric( .getRowValues(x, r) ), r)
@@ -39,13 +39,13 @@
 		if (canProcessInMemory(x, 3)) {
 			x <- setValues(x, callGeneric(values(x), digits))
 			if (digits == 0) {
-				x <- setDatatype(x, 'INT4S')
+				dataType(x) <- 'INT4S'
 			}
 			return(x)
 		} else {
 			rst <- raster(x, filename=tempfile())
 			if (digits == 0) {
-				x <- setDatatype(x, 'INT4S')
+				dataType(x) <- 'INT4S'
 			}
 			for (r in 1:nrow(x)) {
 				rst <- setValues(rst, callGeneric(.getRowValues(x, r), digits), r)

Modified: pkg/raster/R/Merge.R
===================================================================
--- pkg/raster/R/Merge.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/Merge.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -34,7 +34,7 @@
 		}
 	}
 	if (isInt) { 
-		outraster <- setDatatype(outraster, 'INT4S') 
+		dataType(outraster) <- 'INT4S'
 	}
 	
 	rowcol <- matrix(0, ncol=3, nrow=length(rasters))

Modified: pkg/raster/R/aggregate.R
===================================================================
--- pkg/raster/R/aggregate.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/aggregate.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -39,7 +39,7 @@
 	xmx <- xmin(x) + csteps * xfact * xres(x)
 		
 	outRaster <- raster(x, filename)
-	outRaster <- setDatatype(outRaster, datatype)
+	dataType(outRaster) <- datatype
 	bndbox <- newBbox(xmin(x), xmx, ymn, ymax(x))
 	outRaster <- setExtent(outRaster, bndbox, keepres=FALSE)
 	outRaster <- setRowCol(outRaster, nrows=rsteps, ncols=csteps) 

Modified: pkg/raster/R/calc.R
===================================================================
--- pkg/raster/R/calc.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/calc.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -18,7 +18,7 @@
 	
 	filename <- trim(filename)
 	outraster <- raster(x, filename)
-	outraster <- setDatatype(outraster, datatype)
+	dataType(outraster) <- datatype
 	
 	if (!(dataContent(x) == 'all' | dataContent(x) == 'sparse' | dataSource(x) == 'disk')) {
 		stop('RasterLayer has no data on disk, nor a complete set of values in memory')

Modified: pkg/raster/R/calcStack.R
===================================================================
--- pkg/raster/R/calcStack.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/calcStack.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -17,7 +17,7 @@
 
 	filename <- trim(filename)
 	outraster <- raster(x, filename)
-	outraster <- setDatatype(outraster, datatype)
+	dataType(outraster) <- datatype
 	if (dataContent(x) == "all") {
 		outraster <- setValues(outraster, apply(values(x), 1, fun)) 
 		if (filename != "") {

Modified: pkg/raster/R/copyRaster.R
===================================================================
--- pkg/raster/R/copyRaster.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/copyRaster.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -8,7 +8,7 @@
 saveAs <- function(raster, filename, filetype='raster', datatype='FLT4S', overwrite=FALSE) {
 	
 	if (dataContent(raster) == 'all') {
-		raster <- setDatatype(raster, datatype)
+		dataType(raster) <- datatype
 		filename(raster) <- filename
 		writeRaster(raster, filetype=filetype, overwrite=overwrite)
 		return(raster)
@@ -21,7 +21,7 @@
 # if filetype and datatype are the same, then use copyRasterfile 
 
 	newr <- raster(raster, filename)
-	newr <- setDatatype(newr, datatype)
+	dataType(newr) <- datatype
 	for (r in 1:nrow(newr)) {
 		raster <- readRow(raster, r)
 		newr <- setValues(newr, values(raster), r)

Modified: pkg/raster/R/cover.R
===================================================================
--- pkg/raster/R/cover.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/cover.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -16,7 +16,7 @@
 	compare(c(x, y))
 	
 	outRaster <- raster(x, filename)
-	outRaster <- setDatatype(outRaster, datatype)
+	dataType(outRaster) <- datatype
 	
 	# need to check the datatype. if x = INT and y = FLT, result should be FLT?
 	

Modified: pkg/raster/R/depracated.R
===================================================================
--- pkg/raster/R/depracated.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/depracated.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -3,6 +3,14 @@
 #	stop("'newRaster' is deprecated. Use 'raster' instead")
 #}
 
+
+setDatatype <- function(x, value) {
+	warning('depracated function. Use "dataType(x) <- value"')
+	dataType(x) <- value
+	return(x)
+}
+
+
 setRaster <- function(object, filename="", values=NULL) {
 	warning('depracated, use "raster()" instead')
 	return(raster(x=object, filename=filename, values=values))

Modified: pkg/raster/R/disaggregate.R
===================================================================
--- pkg/raster/R/disaggregate.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/disaggregate.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -21,7 +21,7 @@
 	}
 	
 	outraster <- raster(raster, filename)
-	outraster <- setDatatype(outraster, datatype)
+	dataType(outraster) <- datatype
 	outraster <- setRowCol(outraster, nrow(raster) * yfact, ncol(raster) * xfact) 
 
 	if ( dataContent(raster)=='all') {

Modified: pkg/raster/R/init.R
===================================================================
--- pkg/raster/R/init.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/init.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -8,7 +8,7 @@
 init <- function(raster, fun=runif, filename="", overwrite=FALSE, datatype = 'FLT4S', filetype='raster', track=-1) {
 
 	outraster <- raster(raster, filename)
-	outraster <- setDatatype(outraster, datatype)
+	dataType(outraster) <- datatype
 	
 	if ( dataContent(raster) == 'all' | dataSource(raster) == 'ram' ) {
 		n <- ncell(raster)

Modified: pkg/raster/R/linesToRaster.R
===================================================================
--- pkg/raster/R/linesToRaster.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/linesToRaster.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -97,7 +97,7 @@
 		}
 	}
 	raster <- raster(raster, filename)
-	raster <- setDatatype(raster, datatype)
+	dataType(raster) <- datatype
 
 	
 	if (class(spLines) == 'SpatialPolygons') {

Modified: pkg/raster/R/neighborhood.R
===================================================================
--- pkg/raster/R/neighborhood.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/neighborhood.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -49,7 +49,7 @@
 	
 	filename <- trim(filename)
 	ngbgrid <- raster(raster, filename)
-	ngbgrid <- setDatatype(ngbgrid, datatype) 
+	dataType(ngbgrid) <- datatype
 
 # first create an empty matrix with nrows = ngb and ncols = raster at ncols
 	ngbdata1 <- array(data = NA, dim = c(ngb, ncol(raster)))

Modified: pkg/raster/R/overlayList.R
===================================================================
--- pkg/raster/R/overlayList.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/overlayList.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -10,7 +10,7 @@
 	compare(x)
 
 	outraster <- raster(x[[1]], filename)
-	outraster <- setDatatype(outraster, datatype) 
+	dataType(outraster) <- datatype
 
 	inram <- TRUE
 	for (i in 1:length(x)) {

Modified: pkg/raster/R/pointsToRaster.R
===================================================================
--- pkg/raster/R/pointsToRaster.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/pointsToRaster.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -11,7 +11,7 @@
 	xy <- .pointsToMatrix(xy)
 	
 	rs <- raster(raster, filename)
-	rs <- setDatatype(rs, datatype)
+	dataType(rs) <- datatype
 	
 	cells <- cellFromXY(rs, xy)
 	rows <- rowFromCell(rs, cells)

Modified: pkg/raster/R/polygonToRaster.R
===================================================================
--- pkg/raster/R/polygonToRaster.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/polygonToRaster.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -70,7 +70,7 @@
 		}
 	}
 	raster <- raster(raster, filename)
-	raster <- setDatatype(raster, datatype)
+	dataType(raster) <- datatype
 
 	starttime <- proc.time()
 
@@ -231,7 +231,7 @@
 # check if bbox of raster and spPolys overlap
 	filename <- trim(filename)
 	raster <- raster(raster, filename)
-	raster <- setDatatype(raster, datatype)
+	dataType(raster) <- datatype
 	
 
 	spbb <- bbox(spPolys)

Modified: pkg/raster/R/project.R
===================================================================
--- pkg/raster/R/project.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/project.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -47,7 +47,7 @@
 	if (!method %in% c('bilinear', 'ngb')) { stop('invalid method') 	}
 	if (is.null(filename)){filename <- ""}
 	to <- raster(to, filename)
-	to <- setDatatype(to, datatype)
+	dataType(to) <- datatype
 
 	rowCells <- 1:ncol(to)
 	inMemory <- to at file@name == ""

Modified: pkg/raster/R/rasterFromFile.R
===================================================================
--- pkg/raster/R/rasterFromFile.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/rasterFromFile.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -57,7 +57,7 @@
 	raster at data@haveminmax <- TRUE
 	raster at file@nodatavalue <- nodataval
 	
-	raster <- setDatatype(raster, inidatatype)
+	dataType(raster) <- inidatatype
 
 	if ((byteorder == "little") | (byteorder == "big")) { raster at file@byteorder <- byteorder } 	
 	raster at file@nbands <- as.integer(nbands)

Modified: pkg/raster/R/rasterFromFileGDAL.R
===================================================================
--- pkg/raster/R/rasterFromFileGDAL.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/rasterFromFileGDAL.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -34,7 +34,7 @@
 
 	raster <- raster(ncols=nc, nrows=nr, xmn=xn, ymn=yn, xmx=xx, ymx=yx, projs="")
 	filename(raster) <- filename
-	raster <- setDatatype(raster, "FLT4S")
+	dataType(raster) <- "FLT4S"
 	
 
 #	raster at file@driver <- 'gdal' 

Modified: pkg/raster/R/reclass.R
===================================================================
--- pkg/raster/R/reclass.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/reclass.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -22,7 +22,7 @@
 	}
 	
 	outraster <- raster(raster, filename)
-	outraster <- setDatatype(outraster, datatype) 
+	dataType(outraster) <- datatype
 
 	res <- vector(length = ncol(raster))
 	

Modified: pkg/raster/R/replaceProperties.R
===================================================================
--- pkg/raster/R/replaceProperties.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/replaceProperties.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -5,11 +5,7 @@
 # Licence GPL v3
 
 
-'dataType<-' <- function(x, value) {
-	return( setDatatype(x, value) )
-}
 
-
 'ncol<-' <- function(x, value) {
 	return( setRowCol(x, ncols=value) )
 }	

Modified: pkg/raster/R/resample.R
===================================================================
--- pkg/raster/R/resample.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/resample.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -13,7 +13,7 @@
 	validObject(bb)
 	if (is.null(filename)){filename <- ""}
 	to <- raster(to, filename)
-	to <- setDatatype(to, datatype)
+	dataType(to) <- datatype
 	
 	if (!canProcessInMemory(to, 1) && filename(to) == '') {
 		filename <- tempfile()

Modified: pkg/raster/R/setDatatype.R
===================================================================
--- pkg/raster/R/setDatatype.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/setDatatype.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -4,7 +4,8 @@
 # Version 0.8
 # Licence GPL v3
 
-setDatatype <- function(x, value) {
+
+'dataType<-' <- function(x, value) {
 # for backward compatibility issues and non fatal mistakes.
 	datatype <- substr( toupper( trim(value) ), 1, 5)
 	if (datatype=='LOGIC') {datatype <- 'LOG1S'}

Modified: pkg/raster/R/writeRaster.R
===================================================================
--- pkg/raster/R/writeRaster.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/writeRaster.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -39,19 +39,19 @@
 	
 	if ( dtype =='INT') {
 		if (xmin(raster) > -32767 & xmax(raster) < 32768) {
-			raster <- setDatatype(raster, 'INT2S')
+			dataType(raster) <- 'INT2S'
 			raster at data@values <- as.integer(round(values(raster)))
 			raster at data@values[is.na(raster at data@values)] <- as.integer(raster at file@nodatavalue)						
 		} else if (xmin(raster) > -2147483647 & xmax(raster) < 2147483648 ) {
-			raster <- setDatatype(raster, 'INT4S')
+			dataType(raster) <- 'INT4S'
 			raster at data@values <- as.integer(round(values(raster)))
 			raster at data@values[is.na(raster at data@values)] <- as.integer(raster at file@nodatavalue)			
 		} else if (xmin(raster) > -(2^63/2) & xmax(raster) < (2^64/2)) {
-			raster <- setDatatype(raster, 'INT8S')
+			dataType(raster) <- 'INT8S'
 			raster at data@values <- as.integer(round(values(raster)))
 			raster at data@values[is.na(raster at data@values)] <- as.integer(raster at file@nodatavalue)			
 		} else {
-			raster <- setDatatype(raster, 'FLT8S')
+			dataType(raster) <- 'FLT8S'
 			raster at data@values <- as.numeric(values(raster))
 		}
 	} else if ( dtype =='LOGICAL') {
@@ -59,9 +59,9 @@
 		raster at data@values[is.na(raster at data@values)] <- as.integer(raster at file@nodatavalue)
 	} else {
 		if (xmin(raster) < -3.4E38 | xmax(raster) > 3.4E38) {
-			raster <- setDatatype(raster, 'FLT8S')
+			dataType(raster) <- 'FLT8S'
 		} else {
-			raster <- setDatatype(raster, 'FLT4S')
+			dataType(raster) <- 'FLT4S'
 		}	
 	}
 

Modified: pkg/raster/R/writeRasterSparse.R
===================================================================
--- pkg/raster/R/writeRasterSparse.R	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/R/writeRasterSparse.R	2009-03-19 08:54:11 UTC (rev 373)
@@ -19,7 +19,7 @@
 		raster at data@values <- as.integer(values(raster)) 
 	}
 	if (class(values(raster))=='integer') {
-		raster <- setDatatype(raster, 'INT4S')
+		dataType(raster) <- 'INT4S'
 	}	
 	raster <- setMinMax(raster)
 

Modified: pkg/raster/man/setDatatype.Rd
===================================================================
--- pkg/raster/man/setDatatype.Rd	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/man/setDatatype.Rd	2009-03-19 08:54:11 UTC (rev 373)
@@ -11,7 +11,6 @@
 }
 
 \usage{
-setDatatype(x, value)
 dataType(x) <- value
 }
 
@@ -23,8 +22,6 @@
 \details{
 Setting the data type is useful if you want to write values to disk. In other cases use functions such as round()
 
-While you can access the slots of the object directly, you would do that at your own peril because the value of one raster property can affect values in other properties, and changing slot values may thus break the integrity of the objects. Using slots directly may also lead to code to break in the future if underlying class definitions change. 
-
 Datatypes are described by 5 characters. The first three indicate whether the values are integers, decimal number or logical values. The fourth character indicates the number of bytes used to save the values on disk, and the last character indicates whether the numbers are signed (i.e. negative and positive values) or not (only zero and positive values)
 
 The following datatypes are available.
@@ -58,17 +55,15 @@
 \examples{ 
 r <- raster()
 # 2 byte signed integer
-r <- setDatatype(r, "INT2S")
-# this is equivalent to 
 dataType(r) <- "INT2S"
 # 2 byte unsigned integer
-r <- setDatatype(r, "INT2U")
+dataType(r) <- "INT2U"
 # very large integers
-r <- setDatatype(r, "INT8S")
+dataType(r) <- "INT8S"
 # single byte values (0-255)
-r <- setDatatype(r, "INT1U")
+dataType(r) <- "INT1U"
 #double precision decimal numbers
-r <- setDatatype(r, "FLT8S")
+dataType(r) <- "FLT8S"
 }
 
 \keyword{ spatial }

Modified: pkg/raster/man/writeRaster.Rd
===================================================================
--- pkg/raster/man/writeRaster.Rd	2009-03-19 08:45:54 UTC (rev 372)
+++ pkg/raster/man/writeRaster.Rd	2009-03-19 08:54:11 UTC (rev 373)
@@ -59,21 +59,21 @@
 
 # write all to a new binary file
 filename(rst) <- "binall.grd"
-rst <- writeRaster(rst, overwrite=TRUE)
+writeRaster(rst, overwrite=TRUE)
 
 # write all to a new ERDAS .img file
 filename(rst) <- "binall.img"
-rst <- writeRaster(rst, filetype="HFA", overwrite=TRUE)
+writeRaster(rst, filetype="HFA", overwrite=TRUE)
 
  
 # write all to an integer binary file
 filename(rst) <- "binallint.grd"
 dataType(rst) <- "INT4S"
-rst <- writeRaster(rst, overwrite=TRUE)
+writeRaster(rst, overwrite=TRUE)
  
 # write all to ascii file
 filename(rst) <- "ascall.asc"
-rst <- writeRaster(rst, filetype='ascii', overwrite=TRUE)
+writeRaster(rst, filetype='ascii', overwrite=TRUE)
  
 # read and write row by row; write to ascii file
 rst <- raster(system.file("external/test.ag", package="sp"))



More information about the Raster-commits mailing list