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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Feb 8 09:16:15 CET 2009


Author: rhijmans
Date: 2009-02-08 09:16:14 +0100 (Sun, 08 Feb 2009)
New Revision: 261

Added:
   pkg/raster/man/pointsToRaster.Rd
Removed:
   pkg/raster/man/pointToRaster.Rd
Modified:
   pkg/raster/R/polygonToRaster.R
   pkg/raster/R/raster.create.R
   pkg/raster/R/read.raster.R
   pkg/raster/R/writeRaster.R
   pkg/raster/man/LinesToRaster.Rd
Log:


Modified: pkg/raster/R/polygonToRaster.R
===================================================================
--- pkg/raster/R/polygonToRaster.R	2009-02-08 06:27:57 UTC (rev 260)
+++ pkg/raster/R/polygonToRaster.R	2009-02-08 08:16:14 UTC (rev 261)
@@ -97,7 +97,9 @@
 		nsubpol <- length(spPolys at polygons[[i]]@Polygons)
 		for (j in 1:nsubpol) {
 			cnt <- cnt + 1
-			if (cnt > dim(polinfo)[1]) { rbind(polinfo, addpol)  }
+			if (cnt > dim(polinfo)[1]) { 
+				polinfo <- rbind(polinfo, addpol)  
+			}
 			polinfo[cnt, 1] <- cnt
 			polinfo[cnt, 2] <- min(spPolys at polygons[[i]]@Polygons[[j]]@coords[,2])
 			polinfo[cnt, 3] <- max(spPolys at polygons[[i]]@Polygons[[j]]@coords[,2])
@@ -112,6 +114,7 @@
 		}
 	}
 	
+	print(paste('Found', npol, 'regions and ', cnt, 'polygons'))
 	polinfo <- subset(polinfo, polinfo[,1] <= cnt, drop=FALSE)
 #	polinfo <- polinfo[order(polinfo[,1]),]
 	

Modified: pkg/raster/R/raster.create.R
===================================================================
--- pkg/raster/R/raster.create.R	2009-02-08 06:27:57 UTC (rev 260)
+++ pkg/raster/R/raster.create.R	2009-02-08 08:16:14 UTC (rev 261)
@@ -180,7 +180,8 @@
 	} else { datatp="numeric" }
 	datasz <- as.integer(substr(inidatatype, 4, 4))
 	dsign <- substr(inidatatype, 5, 1)
-	raster <- setDatatype(raster, datatype=datatp, datasize=datasz, signed=dsign)
+	if (dsign == 'U') {signed <- FALSE} else {signed <- TRUE}
+	raster <- setDatatype(raster, datatype=datatp, datasize=datasz, signed=signed)
 	if ((byteorder == "little") | (byteorder == "big")) { raster at file@byteorder <- byteorder } 	
 	raster at file@nbands <- as.integer(nbands)
 	raster at file@band <- as.integer(band)

Modified: pkg/raster/R/read.raster.R
===================================================================
--- pkg/raster/R/read.raster.R	2009-02-08 06:27:57 UTC (rev 260)
+++ pkg/raster/R/read.raster.R	2009-02-08 08:16:14 UTC (rev 261)
@@ -203,21 +203,23 @@
 				dd <- c(dd, values(raster)[cols])
 			}	
 		}	
+	}
+	if (asRaster) {
 		outras <- setRaster(raster)
 		outras <- setRowCol(outras, nr, nc)
 		xmx <- xmax(raster) - (ncol(raster) - cols[nc]) * xres(raster)
 		ymn <- ymin(raster) + (nrow(raster) - row) * yres(raster)
 		bndbox <- changeBbox(raster, xmx=xmx, ymn=ymn)
 		outras <- setBbox(outras, bndbox, keepres=F)
-		outras at data@values <- dd
-	}
-	if (asRaster) {
+		outras <- setValues(outras, dd)
 		return(outras)
 	} else {
-		return(values(outras))
+		return(dd)
 	}	
 }
 
+
+
 #.readrandom
 #			if (length(na.omit(values(x))) > maxcell) {
 #				v <- na.omit(cbind(values(x), values(y)))

Modified: pkg/raster/R/writeRaster.R
===================================================================
--- pkg/raster/R/writeRaster.R	2009-02-08 06:27:57 UTC (rev 260)
+++ pkg/raster/R/writeRaster.R	2009-02-08 08:16:14 UTC (rev 261)
@@ -191,22 +191,8 @@
 	cat("yres=", yres(raster), "\n", file = thefile)
 	cat("projection=", projection(raster), "\n", file = thefile)
 	cat("[data]", "\n", file = thefile)
-	if (raster at file@datatype == 'ascii') {  
-		datatype <- "ASC" 
-	} else if (raster at file@datatype == 'integer') {  
-		datatype <- "INT"  
-	} else if (raster at file@datatype == 'logical') {  
-		datatype <- "LOG" 
-	} else { 
-		datatype <- "FLT" 
-	}
-	
-	
-	if (datatype != "ASC") {
-		datatype <- paste(datatype, raster at file@datasize, "BYTES", sep="")
-		cat("DataType=",  datatype, "\n", file = thefile)
-		cat("ByteOrder=",  .Platform$endian, "\n", file = thefile)
-	}	
+	cat("DataType=",  raster at file@datanotation, "\n", file = thefile)
+	cat("ByteOrder=",  .Platform$endian, "\n", file = thefile)
 	cat("nbands=",  nbands(raster), "\n", file = thefile)
 	cat("bandOrder=",  raster at file@bandorder, "\n", file = thefile)
 	cat("minValue=",  minValue(raster), "\n", file = thefile)

Modified: pkg/raster/man/LinesToRaster.Rd
===================================================================
--- pkg/raster/man/LinesToRaster.Rd	2009-02-08 06:27:57 UTC (rev 260)
+++ pkg/raster/man/LinesToRaster.Rd	2009-02-08 08:16:14 UTC (rev 261)
@@ -2,9 +2,9 @@
 
 \alias{linesToRaster}
 
-\title{ Transfer lines to a RasterLayer }
+\title{Transfer lines to a RasterLayer }
 \description{
-  Lines to raster conversion
+  Lines to raster conversion. Lines are raserized.
 }
 \usage{
 linesToRaster(spLines, raster, field=0, filename="", overwrite=FALSE, updateRaster=FALSE, updateValue="NA") 

Deleted: pkg/raster/man/pointToRaster.Rd
===================================================================
--- pkg/raster/man/pointToRaster.Rd	2009-02-08 06:27:57 UTC (rev 260)
+++ pkg/raster/man/pointToRaster.Rd	2009-02-08 08:16:14 UTC (rev 261)
@@ -1,43 +0,0 @@
-\name{ point to raster conversion}
-\alias{pointsToRaster}
-
-\title{ Point to raster diversity functions }
-\description{
-  Convert points to a RasterLayer object
-}
-\usage{
-pointsToRaster(raster, xy, values=rep(1, length(xy[,1])), fun=length, filename="", overwrite=FALSE)
-}
-
-\arguments{
-  \item{raster}{ a RasterLayer object }
-  \item{xy}{ a matrix of x and y coordinates (in the same map reference system as the raster) }
-  \item{filename}{ output filename }
-  \item{overwrite}{if \code{TRUE}, the file will be overwritten if it exists}  
-  \item{values}{a vector of length xy[,1] with the values to be used}  
-  \item{fun}{ the function to be applied}
-}
-
-\details{
-Each point is assinged to a grid cell. The value of a grid cell is determined by the values associated with the points and function fun.
-If you want the count of points in each grid cell, use the (default) \code{length} function. I.e. for each cell it computes the length of the vector of points.
-If you want the sum of the values, use \code{sum} for the sum.
-If you want a yes/no result, you can use fun=function(x){if(lenght(x)>0 {r<-1} else {r<-0}; return(r)}
-}
-\value{
-  a RasterLayer object
-}
-\author{Robert J. Hijmans}
-
-\seealso{ \code{\link[raster]{linesToRaster}}, \code{\link[raster]{polygonsToRaster}}}
-
-\examples{
-r <- raster(ncols=36, nrows=18)
-n <- 1000
-x <- runif(n)* 360 - 180
-y <- runif(n)* 180 - 90
-xy <- cbind(x, y)
-vals <- rep(1, n)
-r <- pointsToRaster(r, xy, vals)
-}
-\keyword{ spatial }

Added: pkg/raster/man/pointsToRaster.Rd
===================================================================
--- pkg/raster/man/pointsToRaster.Rd	                        (rev 0)
+++ pkg/raster/man/pointsToRaster.Rd	2009-02-08 08:16:14 UTC (rev 261)
@@ -0,0 +1,43 @@
+\name{point to raster conversion}
+\alias{pointsToRaster}
+
+\title{ Point to raster conversion }
+\description{
+  Convert points to a RasterLayer object
+}
+\usage{
+pointsToRaster(raster, xy, values=rep(1, length(xy[,1])), fun=length, filename="", overwrite=FALSE)
+}
+
+\arguments{
+  \item{raster}{ a RasterLayer object }
+  \item{xy}{ a matrix of x and y coordinates (in the same map reference system as the raster) }
+  \item{filename}{ output filename }
+  \item{overwrite}{if \code{TRUE}, the file will be overwritten if it exists}  
+  \item{values}{a vector of length xy[,1] with the values to be used}  
+  \item{fun}{ the function to be applied}
+}
+
+\details{
+Each point is assinged to a grid cell. The value of a grid cell is determined by the values associated with the points and function fun.
+If you want the count of points in each grid cell, use the (default) \code{length} function. I.e. for each cell it computes the length of the vector of points.
+If you want the sum of the values, use \code{sum} for the sum.
+If you want a yes/no result, you can use fun=function(x){if(lenght(x)>0 {r<-1} else {r<-0}; return(r)}
+}
+\value{
+  a RasterLayer object
+}
+\author{Robert J. Hijmans}
+
+\seealso{ \code{\link[raster]{linesToRaster}}, \code{\link[raster]{polygonsToRaster}}}
+
+\examples{
+r <- raster(ncols=36, nrows=18)
+n <- 1000
+x <- runif(n)* 360 - 180
+y <- runif(n)* 180 - 90
+xy <- cbind(x, y)
+vals <- rep(1, n)
+r <- pointsToRaster(r, xy, vals)
+}
+\keyword{ spatial }



More information about the Raster-commits mailing list