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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Mar 13 16:54:27 CET 2009


Author: rhijmans
Date: 2009-03-13 16:54:27 +0100 (Fri, 13 Mar 2009)
New Revision: 351

Modified:
   pkg/raster/R/Artith.R
   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/crop.R
   pkg/raster/R/dataProperties.R
   pkg/raster/R/disaggregate.R
   pkg/raster/R/distance.R
   pkg/raster/R/expand.R
   pkg/raster/R/init.R
   pkg/raster/R/linesToRaster.R
   pkg/raster/R/map.R
   pkg/raster/R/na.R
   pkg/raster/R/neighborhood.R
   pkg/raster/R/overlay.R
   pkg/raster/R/pointdistance.R
   pkg/raster/R/pointsToRaster.R
   pkg/raster/R/polygonToRaster.R
   pkg/raster/R/project.R
   pkg/raster/R/raster.R
   pkg/raster/R/readSkip.R
   pkg/raster/R/reclass.R
   pkg/raster/R/replaceProperties.R
   pkg/raster/R/resample.R
   pkg/raster/R/set.R
   pkg/raster/R/stack.R
   pkg/raster/R/stackAdd.R
   pkg/raster/R/summary.R
   pkg/raster/R/writeAscii.R
   pkg/raster/R/writeGDAL.R
   pkg/raster/man/RasterLayer-class.Rd
   pkg/raster/man/cellValues.Rd
   pkg/raster/man/changeStack.Rd
   pkg/raster/man/click.Rd
   pkg/raster/man/copyRasterFile.Rd
   pkg/raster/man/dataContent.Rd
   pkg/raster/man/export.Rd
   pkg/raster/man/pointdistance.Rd
   pkg/raster/man/raster.Rd
   pkg/raster/man/rasterFromFile.Rd
   pkg/raster/man/read.Rd
   pkg/raster/man/sample.Rd
   pkg/raster/man/saveAs.Rd
   pkg/raster/man/set.Rd
   pkg/raster/man/setDatatype.Rd
   pkg/raster/man/stack.Rd
   pkg/raster/man/values.Rd
   pkg/raster/man/writeRaster.Rd
   pkg/raster/man/writeadvanced.Rd
   pkg/raster/man/xyFromCell.Rd
Log:


Modified: pkg/raster/R/Artith.R
===================================================================
--- pkg/raster/R/Artith.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/Artith.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -10,9 +10,9 @@
     function(e1, e2){ 
 		if ( compare(c(e1, e2)) ) {
 			if (canProcessInMemory(e1, 4)) {
-				raster <- setRaster(e1, values=callGeneric( as.numeric(.getRasterValues(e1)), .getRasterValues(e2)))
+				raster <- raster(e1, values=callGeneric( as.numeric(.getRasterValues(e1)), .getRasterValues(e2)))
 			} else {
-				raster <- setRaster(e1, filename=tempfile())
+				raster <- raster(e1, filename=tempfile())
 				for (r in 1:nrow(e1)) {
 					raster <- setValues(raster, callGeneric( as.numeric(.getRowValues(e1, r)), .getRowValues(e2, r) ), r)
 					raster <- writeRaster(raster)
@@ -30,9 +30,9 @@
 setMethod("Arith", signature(e1='RasterLayer', e2='numeric'),
     function(e1, e2){ 
 		if (canProcessInMemory(e1, 4)) {
-			return(setRaster(e1, values=callGeneric(as.numeric(.getRasterValues(e1)), e2) ) )
+			return(raster(e1, values=callGeneric(as.numeric(.getRasterValues(e1)), e2) ) )
 		} else {
-			raster <- setRaster(e1, filename=tempfile())
+			raster <- raster(e1, filename=tempfile())
 			for (r in 1:nrow(e1)) {
 				raster <- setValues(raster, callGeneric( as.numeric(.getRowValues(e1, r)), e2) , r) 
 				raster <- writeRaster(raster)
@@ -48,9 +48,9 @@
 setMethod("Arith", signature(e1='numeric', e2='RasterLayer'),
     function(e1, e2){ 
 		if (canProcessInMemory(e2, 4)) {
-			return(setRaster(e2, values=callGeneric(as.numeric(e1), .getRasterValues(e2))))
+			return(raster(e2, values=callGeneric(as.numeric(e1), .getRasterValues(e2))))
 		} else {
-			raster <- setRaster(e2, filename=tempfile())
+			raster <- raster(e2, filename=tempfile())
 			for (r in 1:nrow(e2)) {
 				raster <- setValues(raster, callGeneric(as.numeric(e1), .getRowValues(e2, r)) , r)
 				raster <- writeRaster(raster)

Modified: pkg/raster/R/Compare_Logical.R
===================================================================
--- pkg/raster/R/Compare_Logical.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/Compare_Logical.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -45,13 +45,13 @@
 		if (canProcessInMemory(x, 3)) {
 			return(setValues(x, !values(x)))
 		} else {
-			raster <- setRaster(x, filename=tempfile())
-			raster <- setDatatype(raster, 'LOG1S')
+			rst <- raster(x, filename=tempfile())
+			dataType(rst) <- 'LOG1S'
 			for (r in 1:nrow(x)) {
-				raster <- setValues(raster, !.getRowValues(x, r), r)
-				raster <- writeRaster(raster)
+				rst <- setValues(rst, !.getRowValues(x, r), r)
+				rst <- writeRaster(rst)
 			}
-			return(raster)		
+			return(rst)		
 		}
 	}
 )	
@@ -63,19 +63,19 @@
 		if (!isTRUE(is.atomic(e2) & length(e2)==1)) {
 			stop('second argument should be a single number')
 		}
-		raster <- setRaster(e1)
-		raster <- setDatatype(raster, 'LOG1S')
+		rst <- raster(e1)
+		rst <- setDatatype(rst, 'LOG1S')
 		if (canProcessInMemory(e1, 3)) {
-			raster <- setValues(raster, values=callGeneric(.getRasterValues(e1), rep(e2, ncell(e1)) ) )			
+			rst <- setValues(rst, values=callGeneric(.getRasterValues(e1), rep(e2, ncell(e1)) ) )			
 		} else {
-			raster <- setFilename(raster, filename=tempfile())
+			rst <- setFilename(rst, filename=tempfile())
 			rowrep <- rep(e2, ncol(e1))
 			for (r in 1:nrow(e1)) {
-				raster <- setValues(raster, callGeneric( .getRowValues(e1, r), rowrep ), r)
-				raster <- writeRaster(raster)
+				rst <- setValues(rst, callGeneric( .getRowValues(e1, r), rowrep ), r)
+				rst <- writeRaster(rst)
 			}
 		}
-		return(raster)
+		return(rst)
 	}
 )	
 
@@ -87,19 +87,19 @@
 			stop('first argument should be a single number')
 		}
 		if (canProcessInMemory(e2, 3)) {
-			raster <- setRaster(e2)
-			raster <- setDatatype(raster, 'LOG1S')
-			raster <- setValues(raster, callGeneric(.getRasterValues(e2), rep(e1, ncell(e2)) ) )
+			rst <- raster(e2)
+			dataType(rst) <- 'LOG1S'
+			rst <- setValues(rst, callGeneric(.getRasterValues(e2), rep(e1, ncell(e2)) ) )
 		} else {
-			raster <- setRaster(e2, filename=tempfile())
-			raster <- setDatatype(raster, 'LOG1S')
+			rst <- raster(e2, filename=tempfile())
+			dataType(rst) <- 'LOG1S'
 			rowrep <- rep(e1, ncol(e2))
 			for (r in 1:nrow(e2)) {
-				raster <- setValues(raster, callGeneric( .getRowValues(e2, r), rowrep ), r)
-				raster <- writeRaster(raster)
+				rst <- setValues(rst, callGeneric( .getRowValues(e2, r), rowrep ), r)
+				rst <- writeRaster(rst)
 			}
 		}
-		return(raster)
+		return(rst)
 	}
 )	
 
@@ -109,18 +109,18 @@
 		if (!cond) {
 			stop("Cannot compare RasterLayers that have different BasicRaster attributes. See compare()")
 		}	
-		raster <- setRaster(e1) 
-		raster <- setDatatype(raster, 'LOG1S')
+		rst <- raster(e1) 
+		dataType(rst) <- 'LOG1S'
 		if (canProcessInMemory(e1, 3)) {
-			raster <- setValues(raster, callGeneric(.getRasterValues(e1), .getRasterValues(e2) ) ) 
+			rst <- setValues(rst, callGeneric(.getRasterValues(e1), .getRasterValues(e2) ) ) 
 		} else {
-			raster <- setFilename(raster, filename=tempfile())
+			rst <- setFilename(rst, filename=tempfile())
 			for (r in 1:nrow(e1)) {
-				raster <- setValues(raster, callGeneric( .getRowValues(e1, r), .getRowValues(e2, r) ), r)
-				raster <- writeRaster(raster)
+				rst <- setValues(rst, callGeneric( .getRowValues(e1, r), .getRowValues(e2, r) ), r)
+				rst <- writeRaster(rst)
 			}
 		}
-		return(raster)
+		return(rst)
 	}
 )	
 
@@ -131,18 +131,18 @@
 setMethod("Logic", signature(e1='RasterLayer', e2='RasterLayer'),
     function(e1, e2){ 
 		if ( compare(c(e1, e2)) ) {
-			raster <- setRaster(e1)
-			raster <- setDatatype(raster, 'LOG1S')
+			rst <- raster(e1)
+			rst <- setDatatype(rst, 'LOG1S')
 			if (canProcessInMemory(e1, 3)) {
-				raster <- setValues(raster, callGeneric(.getLogicalValues(e1), .getLogicalValues(e2)))
+				rst <- setValues(rst, callGeneric(.getLogicalValues(e1), .getLogicalValues(e2)))
 			} else {
-				raster <- setFilename(raster, filename=tempfile())
+				rst <- setFilename(rst, filename=tempfile())
 				for (r in 1:nrow(e1)) {
-					raster <- setValues(raster, callGeneric( .getLogicalRowValues(e1, r), .getLogicalRowValues(e2, r) ), r)
-					raster <- writeRaster(raster)
+					rst <- setValues(rst, callGeneric( .getLogicalRowValues(e1, r), .getLogicalRowValues(e2, r) ), r)
+					rst <- writeRaster(rst)
 				}
 			}	
-			return(raster)
+			return(rst)
 		}	
 	}
 )

Modified: pkg/raster/R/Math.R
===================================================================
--- pkg/raster/R/Math.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/Math.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -11,24 +11,24 @@
 		fname <- as.character(sys.call(sys.parent())[[1]])
 		 
 		if (canProcessInMemory(x, 3)) {
-			raster <- setRaster(x, values=callGeneric(.getRasterValues(x)))
+			rst <- raster(x, values=callGeneric(.getRasterValues(x)))
 			if (fname %in% c('floor', 'ceiling', 'trunc')) {
-				raster <- setDatatype(raster, 'INT4S')
+				rst <- setDatatype(rst, 'INT4S')
 			}
 		} else {
-			raster <- setRaster(x, filename=tempfile())
+			rst <- raster(x, filename=tempfile())
 			if (fname %in% c('floor', 'ceiling', 'trunc')) {
-				raster <- setDatatype(raster, 'INT4S')
+				rst <- setDatatype(rst, 'INT4S')
 			}
 			for (r in 1:nrow(x)) {
-				raster <- setValues(raster, callGeneric( .getRowValues(x, r) ), r)
-				raster <- writeRaster(raster)
+				rst <- setValues(rst, callGeneric( .getRowValues(x, r) ), r)
+				rst <- writeRaster(rst)
 			}
 			if (options('verbose')[[1]]) {
 				cat('values were written to:', filename(raster))
 			}
 		}
-		return(raster)
+		return(rst)
 	}
 )
 
@@ -43,15 +43,15 @@
 			}
 			return(x)
 		} else {
-			raster <- setRaster(x, filename=tempfile())
+			rst <- raster(x, filename=tempfile())
 			if (digits == 0) {
 				x <- setDatatype(x, 'INT4S')
 			}
 			for (r in 1:nrow(x)) {
-				raster <- setValues(raster, callGeneric(.getRowValues(x, r), digits), r)
-				raster <- writeRaster(raster)
+				rst <- setValues(rst, callGeneric(.getRowValues(x, r), digits), r)
+				rst <- writeRaster(rst)
 			}
-			return(raster)
+			return(rst)
 		}
 	}
 )

Modified: pkg/raster/R/Merge.R
===================================================================
--- pkg/raster/R/Merge.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/Merge.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -22,7 +22,7 @@
 			
 	compare(rasters, bb=FALSE, rowcol=FALSE, orig=TRUE, res=TRUE, tolerance=tolerance)
 	bb <- unionBbox(rasters)
-	outraster <- setRaster(rasters[[1]], filename)
+	outraster <- raster(rasters[[1]], filename)
 #	bndbox <- newBbox(bb[1,1], bb[1,2], bb[2,1], bb[2,2])
 	outraster <- setExtent(outraster, bb, keepres=TRUE, snap=FALSE)
 

Modified: pkg/raster/R/aggregate.R
===================================================================
--- pkg/raster/R/aggregate.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/aggregate.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -38,7 +38,7 @@
 	ymn <- ymax(x) - rsteps * yfact * yres(x)
 	xmx <- xmin(x) + csteps * xfact * xres(x)
 		
-	outRaster <- setRaster(x, filename)
+	outRaster <- raster(x, filename)
 	outRaster <- setDatatype(outRaster, datatype)
 	bndbox <- newBbox(xmin(x), xmx, ymn, ymax(x))
 	outRaster <- setExtent(outRaster, bndbox, keepres=F)

Modified: pkg/raster/R/calc.R
===================================================================
--- pkg/raster/R/calc.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/calc.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -17,7 +17,7 @@
 	}
 	
 	filename <- trim(filename)
-	outraster <- setRaster(x, filename)
+	outraster <- raster(x, filename)
 	outraster <- setDatatype(outraster, datatype)
 	
 	if (!(dataContent(x) == 'all' | dataContent(x) == 'sparse' | dataSource(x) == 'disk')) {

Modified: pkg/raster/R/calcStack.R
===================================================================
--- pkg/raster/R/calcStack.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/calcStack.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -16,7 +16,7 @@
 	}
 
 	filename <- trim(filename)
-	outraster <- setRaster(x, filename)
+	outraster <- raster(x, filename)
 	outraster <- setDatatype(outraster, datatype)
 	if (dataContent(x) == "all") {
 		outraster <- setValues(outraster, apply(values(x), 1, fun)) 

Modified: pkg/raster/R/copyRaster.R
===================================================================
--- pkg/raster/R/copyRaster.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/copyRaster.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -20,7 +20,7 @@
 
 # if filetype and datatype are the same, then use copyRasterfile 
 
-	newr <- setRaster(raster, filename)
+	newr <- raster(raster, filename)
 	newr <- setDatatype(newr, datatype)
 	for (r in 1:nrow(newr)) {
 		raster <- readRow(raster, r)

Modified: pkg/raster/R/cover.R
===================================================================
--- pkg/raster/R/cover.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/cover.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -15,7 +15,7 @@
 	
 	compare(c(x, y))
 	
-	outRaster <- setRaster(x, filename)
+	outRaster <- raster(x, filename)
 	outRaster <- setDatatype(outRaster, datatype)
 	
 	# need to check the datatype. if x = INT and y = FLT, result should be FLT?

Modified: pkg/raster/R/crop.R
===================================================================
--- pkg/raster/R/crop.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/crop.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -12,7 +12,7 @@
 # we could also allow the raster to expand but for now let's not and first make a separate expand function
 	bb <- intersectBbox(raster, bndbox)
 	bb <- alignBbox(bb, raster)
-	outraster <- setRaster(raster, filename)
+	outraster <- raster(raster, filename)
 	outraster <- setExtent(outraster, bb, keepres=T)
 	
 	if (dataContent(raster) == 'all')  {

Modified: pkg/raster/R/dataProperties.R
===================================================================
--- pkg/raster/R/dataProperties.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/dataProperties.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -6,7 +6,9 @@
 
 #dataSize <- function(object) {return(object at file@datasize)}
 dataSize <- function(object) {
-	if (class(object) != 'character'){object <- dataType(object)}
+	if (class(object) != 'character'){
+		object <- dataType(object)
+	}
 	return( as.integer (substr(object, 4, 4)) )
 }
 

Modified: pkg/raster/R/disaggregate.R
===================================================================
--- pkg/raster/R/disaggregate.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/disaggregate.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -20,7 +20,7 @@
 		stop('length(fact) should be 1 or 2')
 	}
 	
-	outraster <- setRaster(raster, filename)
+	outraster <- raster(raster, filename)
 	outraster <- setDatatype(outraster, datatype)
 	outraster <- setRowCol(outraster, nrow(raster) * yfact, ncol(raster) * xfact) 
 

Modified: pkg/raster/R/distance.R
===================================================================
--- pkg/raster/R/distance.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/distance.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -21,7 +21,7 @@
 				{			
 					adj <- adjacency(object,fromCells=fromCells,toCells=toCells,directions=8)
 					coord <- cbind(xyFromCell(object,adj[,1]),xyFromCell(object,adj[,2]))
-					distance <- apply(coord,1,function(x){distanceGreatcircle(x[1:2],x[3:4])})
+					distance <- apply(coord,1,function(x){pointDistance(x[1:2],x[3:4], type='GreatCircle')})
 					#What follows is the same as for  non-projected (below)
 					transitionValues <- accDist[adj[,1]] + distance
 					transitionValues <- tapply(transitionValues,adj[,2],min)
@@ -56,7 +56,7 @@
 			
 			nrows <- nrow(object)
 			ncols <- ncol(object)
-			outRaster <- setRaster(object, filename)
+			outRaster <- raster(object, filename)
 			for(r in 1:nrows)
 			{
 				rowValues <- valuesRow(readRow(object, rownr = r), rownr = r)
@@ -75,7 +75,7 @@
 						if(r<nrows-1){rowWindow <- c(rowWindow,valuesRow(readRow(outRaster, rownr=r+1), rownr=r+1))}
 						adj <- adjacency(fromCells=(((max(1,r-1))*ncols)+1):(min(nrows,(r+2)*ncols)), toCells=((r-1)*ncols+1):(r*ncols),directions=8)
 						coord <- cbind(xyFromCell(object,adj[,1]),xyFromCell(object,adj[,2]))
-						distance <- apply(coord,1,function(x){distanceGreatcircle(x[1:2],x[3:4])})
+						distance <- apply(coord,1,function(x){pointDistance(x[1:2],x[3:4], type='GreatCircle')})
 						adj <- adj-((r-1)*ncols+1)
 						transitionValues <- as.vector(rowWindow)[adj[,1]] + distance
 						transitionValues <- tapply(transitionValues,adj[,2],min)

Modified: pkg/raster/R/expand.R
===================================================================
--- pkg/raster/R/expand.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/expand.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -24,7 +24,7 @@
 	ymn <- min(ymn, ymin(raster))
 	ymx <- max(ymx, ymax(raster))
 	
-	outraster <- setRaster(raster, filename)
+	outraster <- raster(raster, filename)
 	bndbox <- newBbox(xmn, xmx, ymn, ymx)
 	outraster <- setExtent(outraster, bndbox, keepres=T)
 

Modified: pkg/raster/R/init.R
===================================================================
--- pkg/raster/R/init.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/init.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -7,7 +7,7 @@
 
 init <- function(raster, fun=runif, filename="", overwrite=FALSE, datatype = 'FLT4S', filetype='raster', track=-1) {
 
-	outraster <- setRaster(raster, filename)
+	outraster <- raster(raster, filename)
 	outraster <- setDatatype(outraster, datatype)
 	
 	if ( dataContent(raster) == 'all' | dataSource(raster) == 'ram' ) {

Modified: pkg/raster/R/linesToRaster.R
===================================================================
--- pkg/raster/R/linesToRaster.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/linesToRaster.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -96,7 +96,7 @@
 			stop('updateValue should be either "all", "NA", "!NA", or "zero"')
 		}
 	}
-	raster <- setRaster(raster, filename)
+	raster <- raster(raster, filename)
 	raster <- setDatatype(raster, datatype)
 
 	

Modified: pkg/raster/R/map.R
===================================================================
--- pkg/raster/R/map.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/map.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -10,7 +10,7 @@
 #TODO if xlim and/or ylim are used, only read (and sample) for those areas.
 #	require(fields)
 	if (class(object) == 'character') { 
-		object <- rasterFromFile(object) 
+		object <- raster(object) 
 	}
 	if ( class(object) != 'RasterLayer' ) { 
 		index <- round(index)
@@ -37,7 +37,7 @@
 			
 			m <- values(object, format='matrix')[rows, cols]
 
-			sampraster <- setRaster(object)
+			sampraster <- raster(object)
 			sampraster <- setRowCol(sampraster, dim(m)[1], dim(m)[2])
 			xmx <- xmax(object) - (ncol(object) - cols[length(cols)]) * xres(object)
 			ymn <- ymin(object) + (nrow(object) - rows[length(rows)]) * yres(object)

Modified: pkg/raster/R/na.R
===================================================================
--- pkg/raster/R/na.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/na.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -7,33 +7,33 @@
 
 setMethod("is.na", signature(x='RasterLayer'),
 	function(x) {
-		raster <- setRaster(x)
-		raster <- setDatatype(raster, 'LOG1S')
-		return(setValues(raster, is.na(.getRasterValues(x))))
+		rst <- raster(x)
+		dataType(rst) <- 'LOG1S'
+		return(setValues(rst, is.na(.getRasterValues(x))))
 	}
 )	
 
 setMethod("is.nan", signature(x='RasterLayer'),
 	function(x) {
-		raster <- setRaster(x)
-		raster <- setDatatype(raster, 'LOG1S')
-		return(setValues(raster, is.nan(.getRasterValues(x))))
+		rst <- raster(x)
+		dataType(rst) <- 'LOG1S'
+		return(setValues(rst, is.nan(.getRasterValues(x))))
 	}
 )	
 
 setMethod("is.infinite", signature(x='RasterLayer'),
 	function(x) {
-		raster <- setRaster(x)
-		raster <- setDatatype(raster, 'LOG1S')
-		return(setValues(raster, values=is.infinite(.getRasterValues(x))))
+		rst <- raster(x)
+		dataType(rst) <- 'LOG1S'
+		return(setValues(rst, values=is.infinite(.getRasterValues(x))))
 	}
 )	
 
 setMethod("is.finite", signature(x='RasterLayer'),
 	function(x) {
-		raster <- setRaster(x)
-		raster <- setDatatype(raster, 'LOG1S')
-		return(setValues(raster, values=is.finite(.getRasterValues(x))))
+		rst <- raster(x)
+		dataType(rst) <- 'LOG1S'
+		return(setValues(rst, values=is.finite(.getRasterValues(x))))
 	}
 )	
 

Modified: pkg/raster/R/neighborhood.R
===================================================================
--- pkg/raster/R/neighborhood.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/neighborhood.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -48,7 +48,7 @@
 	lim <- floor(ngb / 2)
 	
 	filename <- trim(filename)
-	ngbgrid <- setRaster(raster, filename)
+	ngbgrid <- raster(raster, filename)
 	ngbgrid <- setDatatype(ngbgrid, datatype) 
 
 # first create an empty matrix with nrows = ngb and ncols = raster at ncols

Modified: pkg/raster/R/overlay.R
===================================================================
--- pkg/raster/R/overlay.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/overlay.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -39,7 +39,7 @@
 	
 	compare(x)
 
-	outraster <- setRaster(x[[1]], filename)
+	outraster <- raster(x[[1]], filename)
 	outraster <- setDatatype(outraster, datatype) 
 
 	inram <- TRUE

Modified: pkg/raster/R/pointdistance.R
===================================================================
--- pkg/raster/R/pointdistance.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/pointdistance.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -4,82 +4,68 @@
 # Version 0,7
 # Licence GPL v3
 
-distanceEuclidean <- function (point1, point2) {
-	#some checks
 
-	if ( (!is.vector(point1) & !is.matrix(point1)) |  (!is.vector(point2) & !is.matrix(point2)) ) {
-		stop('points can only be supplied vectors of length 2 or matrices with 2 columns')
-	}
 
-	if(is.vector(point1)){
-		if (length(point1) != 2) {stop('wrong length: point1 can only be a vector of length 2 or a matrix with 2 columns')}
-	}
-	if(is.vector(point2)){
-		if (length(point2) != 2) {stop('wrong length: point2 can only be a vector of length 2 or a matrix with 2 columns')}
+pointDistance <- function (point1, point2, type='Euclidean', ...) {
+		
+	if (!(type %in% c('Euclidean', 'GreatCircle'))) {
+		stop('type should be Euclidean or GreatCircle')
 	}	
-	if(is.matrix(point1)){
-		if (length(point1[1,]) != 2) {stop('wrong length: point1 can only be a vector of length 2 or a matrix with 2 columns')}
+	
+	if (class(point1) == 'SpatialPoints' | class(point1) == 'SpatialPointsDataFrame') {
+		point1 <- coordinates(point1)
 	}
-	if(is.matrix(point2)){
-		if (length(point2[1,]) != 2) {stop('wrong length: point2 can only be a vector of length 2 or a matrix with 2 columns')}
+	if (class(point2) == 'SpatialPoints' | class(point2) == 'SpatialPointsDataFrame') {
+		point2 <- coordinates(point2)
 	}
-	if(is.matrix(point1) & is.matrix(point2)){
-		if(length(point1[,1]) != length(point2[,1]))
-			{stop('when point1 and point2 are both matrices they should have the same number of rows')}
+
+	if ( (!is.vector(point1) & !is.matrix(point1)) |  (!is.vector(point2) & !is.matrix(point2)) ) {
+		stop('points should be vectors of length 2, matrices with 2 columns, or a SpatialPoints* object')
 	}
 
-	if(is.vector(point1)){ point1 <- matrix(point1, ncol=2) }
-	if(is.vector(point2)){ point2 <- matrix(point1, ncol=2) }
-	
-	x1 <- point1[,1]
-	y1 <- point1[,2]
-	x2 <- point2[,1]
-	y2 <- point2[,2]
-
-	distance <- sqrt((x1 - x2)^2 + (y1 - y2)^2)
-	return(distance)
-}
-
-
-
-distanceGreatcircle <- function (point1, point2, r=6378137) {
-	# some checks
-	if ( (!is.vector(point1) & !is.matrix(point1)) |  (!is.vector(point2) & !is.matrix(point2)) ) {stop('points can only be supplied vectors of length 2 or matrices with 2 columns')}
-
 	if(is.vector(point1)){
-		if (length(point1) != 2) {stop('wrong length: point1 can only be a vector of length 2 or a matrix with 2 columns')}
+		if (length(point1) != 2) {
+			stop('point1. Wrong length for a vector, should be 2')
+		} else {
+			point1 <- matrix(point1, ncol=2) 
+		}
+	} else {
+		if (length(point1[1,]) != 2) {
+			stop('point1. The matrix should have 2 columns')
+		}
 	}
+
 	if(is.vector(point2)){
-		if (length(point2) != 2) {stop('wrong length: point2 can only be a vector of length 2 or a matrix with 2 columns')}
-	}	
-	if(is.matrix(point1)){
-		if (length(point1[1,]) != 2) {stop('wrong length: point1 can only be a vector of length 2 or a matrix with 2 columns')}
+		if (length(point2) != 2) {
+			stop('point2. Wrong length for a vector, should be 2')
+		} else {
+			point2 <- matrix(point2, ncol=2) 
+		}
+	} else {
+		if (length(point2[1,]) != 2) {
+			stop('point2. The matrix should have 2 columns')
+		}
 	}
-	if(is.matrix(point2)){
-		if (length(point2[1,]) != 2) {stop('wrong length: point2 can only be a vector of length 2 or a matrix with 2 columns')}
+	
+	if(length(point1[,1]) != length(point2[,1])) {
+		if(length(point1[,1]) > 1 & length(point2[,1]) > 1) {
+			stop('point1 and point2 do not have the same number of rows; and neither has only a single row')
+		}
 	}
-	if(is.matrix(point1) & is.matrix(point2)){
-		if(length(point1[,1]) != length(point2[,1]))
-			{stop('when point1 and point2 are both matrices they should have the same number of rows')}
-	}
 	
-	# from degrees t o radians
-	point1 <- point1 * pi / 180
-	point2 <- point2 * pi / 180	
+	if (type == 'Euclidean') {
+		return ( sqrt(( point1[,1] -  point2[,1])^2 + (point1[,2] - point2[,2])^2) )
+	} else { 
+		return(.greatCircleDist(point1[,1], point1[,2], point2[,1], point2[,2], ...) )
+	}
+}
 
-	if(is.vector(point1)){ point1 <- matrix(point1, ncol=2) }
-	if(is.vector(point2)){ point2 <- matrix(point1, ncol=2) }
-	
-	x1 <- point1[,1]
-	y1 <- point1[,2]
-	x2 <- point2[,1]
-	y2 <- point2[,2]
 
+.greatCircleDist <- function(x1, y1, x2, y2, r = 6378137) {
 	#	cosd <- sin(y1) * sin(y2) + cos(y1) * cos(y2) * cos(x1-x2);
 	#	distance <- r * acos(cosd);
 	#  the following is supposedly more precise than above (http://en.wikipedia.org/wiki/Great_circle_distance):
 	x <- sqrt((cos(y2) * sin(x1-x2))^2 + (cos(y1) * sin(y2) - sin(y1) * cos(y2) * cos(x1-x2))^2)
 	y <- sin(y1) * sin(y2) + cos(y1) * cos(y2) * cos(x1-x2)
-	distance <- r * atan2(x, y)
-	return(distance)
+	return ( r * atan2(x, y) )
 }

Modified: pkg/raster/R/pointsToRaster.R
===================================================================
--- pkg/raster/R/pointsToRaster.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/pointsToRaster.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -15,7 +15,7 @@
 		stop('values must be a vector of length=length(xy[,1])')
 	}
 	
-	rs <- setRaster(raster, filename)
+	rs <- raster(raster, filename)
 	rs <- setDatatype(rs, datatype)
 	
 	cells <- cellFromXY(rs, xy)

Modified: pkg/raster/R/polygonToRaster.R
===================================================================
--- pkg/raster/R/polygonToRaster.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/polygonToRaster.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -70,7 +70,7 @@
 			stop('updateValue should be either "all", "NA", "!NA", or "zero"')
 		}
 	}
-	raster <- setRaster(raster, filename)
+	raster <- raster(raster, filename)
 	raster <- setDatatype(raster, datatype)
 
 # check if bbox of raster and spPolys overlap
@@ -229,7 +229,7 @@
 
 # check if bbox of raster and spPolys overlap
 	filename <- trim(filename)
-	raster <- setRaster(raster, filename)
+	raster <- raster(raster, filename)
 	raster <- setDatatype(raster, datatype)
 	
 

Modified: pkg/raster/R/project.R
===================================================================
--- pkg/raster/R/project.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/project.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -46,7 +46,7 @@
 
 	if (!method %in% c('bilinear', 'ngb')) { stop('invalid method') 	}
 	if (is.null(filename)){filename <- ""}
-	to <- setRaster(to, filename)
+	to <- raster(to, filename)
 	to <- setDatatype(to, datatype)
 
 	rowCells <- 1:ncol(to)

Modified: pkg/raster/R/raster.R
===================================================================
--- pkg/raster/R/raster.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/raster.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -5,33 +5,16 @@
 # Licence GPL v3
 
 
-
-
-
-
 rasterFromFile <- function(filename, values=FALSE, band=1) {
 	warning("'rasterFromFile' is deprecated. Use 'raster(filename)' instead")
-
-	fileext <- toupper(fileExtension(filename)) 
-	if ( fileext == ".GRD" | fileext == ".GRI" ) {
-		raster <- .rasterFromRasterFile(filename, band) 
-	} else {
-		raster <- .rasterFromGDAL(filename, band) 
-	}
-	if (values) {
-		raster <- readAll(raster)
-	}
-	return(raster)
+	return(raster(filename, values=values, band=band))
 }	
 	
-
-
 if (!isGeneric("raster")) {
 	setGeneric("raster", function(x, ...)
 		standardGeneric("raster"))
 }	
 
-
 setMethod('raster', signature(x='missing'), 
 	function(nrows=180, ncols=360, xmn=-180, xmx=180, ymn=-90, ymx=90, projstring="+proj=longlat +datum=WGS84") {
 		bb <- newBbox(xmn, xmx, ymn, ymx)
@@ -41,17 +24,41 @@
 	}
 )
 
+setMethod('raster', signature(x='Raster'), 
+	function(x, filename="", values=NULL) {
+	
+		if (class(x) == 'RasterStack') { 
+			x <- asRasterLayer(x, 1) 
+		}
+		if (class(x) != 'RasterLayer') { stop('the first argument should be a RasterLayer or a RasterStack object') }
 
-setMethod('raster', signature(x='Raster'), 
-	function(x, ...) {
-		return(setRaster(x))
+		filename <- trim(filename)
+		if (filename != "" & filename == filename(x)) {
+			stop("it is not allowed to set the filename of the output RasterLayer to that of the input RasterLayer")
+		}
+
+		r <- raster(xmn = xmin(x), xmx = xmax(x), ymn = ymin(x), ymx = ymax(x), nrows=nrow(x), ncols=ncol(x), projstring=projection(x))
+		r <- setFilename(r, filename)
+	
+		if (!is.null(values)) {
+			r <- setValues(r, values)
+		}
+		return(r)
 	}
 )
 
-
 setMethod('raster', signature(x='character'), 
 	function(x, values=FALSE, band=1) {
-		return(rasterFromFile(x, values=values, band=band))
+		fileext <- toupper(fileExtension(x)) 
+		if ( fileext == ".GRD" | fileext == ".GRI" ) {
+			raster <- .rasterFromRasterFile(x, band) 
+		} else {
+			raster <- .rasterFromGDAL(x, band) 
+		}
+		if (values) {
+			raster <- readAll(raster)
+		}
+		return(raster)
 	}
 )
 

Modified: pkg/raster/R/readSkip.R
===================================================================
--- pkg/raster/R/readSkip.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/readSkip.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -11,7 +11,7 @@
 		rcut <- crop(raster, bndbox) 
 		warning('bndbox option has not been implemented yet')
 	} else {
-		rcut <- setRaster(raster)
+		rcut <- raster(raster)
 	}
 	# Need to do something with this now.....
 	
@@ -46,7 +46,7 @@
 				dd <- c(dd, values(raster)[cols])
 			}	
 		}	
-		outras <- setRaster(raster)
+		outras <- raster(raster)
 		outras <- setRowCol(outras, nr, nc)
 		xmx <- xmax(raster) - (ncol(raster) - cols[nc]) * xres(raster)
 		ymn <- ymin(raster) + (nrow(raster) - row) * yres(raster)

Modified: pkg/raster/R/reclass.R
===================================================================
--- pkg/raster/R/reclass.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/reclass.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -21,7 +21,7 @@
 		print(rclmat)
 	}
 	
-	outraster <- setRaster(raster, filename)
+	outraster <- raster(raster, filename)
 	outraster <- setDatatype(outraster, datatype) 
 
 	res <- vector(length = ncol(raster))

Modified: pkg/raster/R/replaceProperties.R
===================================================================
--- pkg/raster/R/replaceProperties.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/replaceProperties.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -9,7 +9,7 @@
 	return( setFilename(x, value) )
 }
 
-'datatype<-' <- function(x, value) {
+'dataType<-' <- function(x, value) {
 	return( setDatatype(x, value) )
 }
 

Modified: pkg/raster/R/resample.R
===================================================================
--- pkg/raster/R/resample.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/resample.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -12,7 +12,7 @@
 	bb <- intersectBbox(from, to)
 	validObject(bb)
 	if (is.null(filename)){filename <- ""}
-	to <- setRaster(to, filename)
+	to <- raster(to, filename)
 	to <- setDatatype(to, datatype)
 	
 	if (!canProcessInMemory(to, 1) && filename(to) == '') {

Modified: pkg/raster/R/set.R
===================================================================
--- pkg/raster/R/set.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/set.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -32,22 +32,8 @@
 }
 
 setRaster <- function(object, filename="", values=NULL) {
-
-	if (class(object) == 'RasterStack') { object <- asRasterLayer(object, 1) }
-	if (class(object) != 'RasterLayer') { stop('the first argument should be a RasterLayer or a RasterStack object') }
-
-	filename <- trim(filename)
-	if (filename != "" & filename == filename(object)) {
-		stop("it is not allowed to set the filename of the output RasterLayer to that of the input RasterLayer")
-	}
-
-	r <- raster(xmn = xmin(object), xmx = xmax(object), ymn = ymin(object), ymx = ymax(object), nrows=nrow(object), ncols=ncol(object), projstring=projection(object))
-	r <- setFilename(r, filename)
-	
-	if (!is.null(values)) {
-		r <- setValues(r, values)
-	}
-	return(r)
+	warning('depracated, use "raster()" instead')
+	return(raster(object, filename, values))
 }
 
 setFilename <- function(object, filename) {

Modified: pkg/raster/R/stack.R
===================================================================
--- pkg/raster/R/stack.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/stack.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -42,15 +42,15 @@
 		j <- j + 1
 		if (is.character(x[[i]])) {
 			if (is.null(bands)) {
-				r[j] <- rasterFromFile(x[[i]])
+				r[j] <- raster(x[[i]])
 			} else {
 				if (bands[[i]] < 1) {
-					r[j] <- rasterFromFile(x[[i]], 1)
+					r[j] <- raster(x[[i]], 1)
 					bds <- nbands(r)
 					if (bds > 1) {
 						for (b in 2:bds) {
 							j <- j + 1
-							r[j] <- rasterFromFile(x[[i]], b)
+							r[j] <- raster(x[[i]], b)
 						}
 					}
 				}

Modified: pkg/raster/R/stackAdd.R
===================================================================
--- pkg/raster/R/stackAdd.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/stackAdd.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -13,16 +13,16 @@
 	rasters <- list()
 	for (i in 1:length(rasterfiles)) { 
 		if (bands[[i]] < 1) {
-			r <- rasterFromFile(rasterfiles[[i]], band=1)
+			r <- raster(rasterfiles[[i]], band=1)
 			rasters <- c(rasters, r)
 			if (nbands(r) > 1) {
 				for (j in 2:nbands(r)) {
-					r <- rasterFromFile(rasterfiles[[i]], band=j)
+					r <- raster(rasterfiles[[i]], band=j)
 					rasters <- c(rasters, r)
 				}
 			}
 		} else {
-			rasters <- c(rasters, rasterFromFile(rasterfiles[[i]], FALSE, band=bands[[i]]))
+			rasters <- c(rasters, raster(rasterfiles[[i]], FALSE, band=bands[[i]]))
 		}
 	}	
 	rstack <- addRasters(rstack, rasters) 

Modified: pkg/raster/R/summary.R
===================================================================
--- pkg/raster/R/summary.R	2009-03-13 12:56:52 UTC (rev 350)
+++ pkg/raster/R/summary.R	2009-03-13 15:54:27 UTC (rev 351)
@@ -9,10 +9,10 @@
 
 	if (!canProcessInMemory(rasters[[1]], 4)) {
 		filename <- tempfile()
-		raster <- setRaster(rasters[[1]], filename)
+		raster <- raster(rasters[[1]], filename)
 	} else {
 		filename <- ""
-		raster <- setRaster(rasters[[1]])
+		raster <- raster(rasters[[1]])
 		v <- vector(length=0)
 	}
 

[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/raster -r 351


More information about the Raster-commits mailing list