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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Feb 5 02:33:34 CET 2009


Author: rhijmans
Date: 2009-02-05 02:33:34 +0100 (Thu, 05 Feb 2009)
New Revision: 246

Modified:
   pkg/raster/R/all.classes.R
   pkg/raster/R/click.R
   pkg/raster/R/polygonToRaster.R
   pkg/raster/R/project.R
   pkg/raster/man/project.Rd
Log:


Modified: pkg/raster/R/all.classes.R
===================================================================
--- pkg/raster/R/all.classes.R	2009-02-04 09:32:22 UTC (rev 245)
+++ pkg/raster/R/all.classes.R	2009-02-05 01:33:34 UTC (rev 246)
@@ -22,8 +22,13 @@
 	),
 	validity = function(object)	{
 		c1 <- (object at xmin <= object at xmax)
+		if (!c1) { stop('xmin > xmax') }
 		c2 <- (object at ymin <= object at ymax)
-		return(c1 & c2)
+		if (!c2) { stop('ymin > ymax') }
+		v <- c(object at xmin, object at xmax, object at ymin, object at ymax)
+		c3 <- all(!is.infinite(v))
+		if (!c3) { stop('infinite in BoundingBox') }		
+		return(c1 & c2 & c3)
 	}
 )
 
@@ -41,8 +46,11 @@
 		crs = CRS(as.character(NA))
 	),
 	validity = function(object) {
+		validObject(getBbox(object))
 		c1 <- (object at ncols > 0)
+		if (!c1) { stop('ncols < 1') }
 		c2 <- (object at nrows > 0)
+		if (!c2) { stop('nrows < 1') }		
 		return(c1 & c2)
 	}
 )
@@ -83,7 +91,7 @@
 	),
 	validity = function(object) {
 	}
-)	
+)
 
 
 setClass('SingleLayerData', 

Modified: pkg/raster/R/click.R
===================================================================
--- pkg/raster/R/click.R	2009-02-04 09:32:22 UTC (rev 245)
+++ pkg/raster/R/click.R	2009-02-05 01:33:34 UTC (rev 246)
@@ -7,6 +7,7 @@
 # Licence GPL v3
 
 BboxToPolygon <- function(bbox) {
+	bbox <- getBbox(bbox)
 	p <- rbind(c(bbox at xmin, bbox at ymin), c(bbox at xmin, bbox at ymax), c(bbox at xmax, bbox at ymax), c(bbox at xmax, bbox at ymin), c(bbox at xmin, bbox at ymin) )
 	pol <- SpatialPolygons(list(Polygons(list(Polygon(p)), 1)))
 	return(pol)

Modified: pkg/raster/R/polygonToRaster.R
===================================================================
--- pkg/raster/R/polygonToRaster.R	2009-02-04 09:32:22 UTC (rev 245)
+++ pkg/raster/R/polygonToRaster.R	2009-02-05 01:33:34 UTC (rev 246)
@@ -1,7 +1,7 @@
 # Author: Robert J. Hijmans, r.hijmans at gmail.com
 # International Rice Research Institute
-# Date :  June 2008
-# Version 0,1
+# Date :  January2008
+# Version 0.8
 # Licence GPL v3
 
 
@@ -59,7 +59,7 @@
 
 
 
-polygonsToRaster <- function(spPolys, raster, field=0, filename="", overwrite=FALSE, updateRaster=FALSE, updateValue="NA") {
+polygonsToRaster <- function(spPolys, raster, field=0, filename="", overwrite=FALSE, updateRaster=FALSE, updateValue="NA", trackRows=0) {
 	filename <- trim(filename)
 	if (updateRaster) {
 		oldraster <- raster 
@@ -78,9 +78,6 @@
 	npol <- length(spPolys at polygons)
 	info <- matrix(NA, nrow=npol, ncol=3)
 	for (i in 1:npol) {
-#		holes <- sapply(rings, function(y) slot(y, "hole"))
-#		areas <- sapply(rings, function(x) slot(x, "area"))
-
 		info[i,1] <- length(spPolys at polygons[[i]]@Polygons)
 		miny <- NULL
 		maxy <- NULL
@@ -109,6 +106,10 @@
 	rxmn <- xmin(raster) + 0.1 * xres(raster)
 	rxmx <- xmax(raster) - 0.1 * xres(raster)
 	for (r in 1:nrow(raster)) {
+		if (r %in% trackRows) {
+			print(paste('row', r, '---', nrow(raster)+1-r, " rows to go"))
+		}
+		
 		rv <- rep(NA, ncol(raster))
 		holes <- rep(FALSE, ncol(raster))
 		

Modified: pkg/raster/R/project.R
===================================================================
--- pkg/raster/R/project.R	2009-02-04 09:32:22 UTC (rev 245)
+++ pkg/raster/R/project.R	2009-02-05 01:33:34 UTC (rev 246)
@@ -29,9 +29,14 @@
 
 
 projectRaster <- function(from, to, method="nngb", overwrite=FALSE) {
+
 # do the bounding boxes overlap at all? 
+
 # get .innerbox first?
+
 # are the projs not NA and valid and not the same?
+
+	validObject(to)
 	rowCells <- 1:ncol(to)
 	inMemory <- filename(to) == ""
 	v <- vector(length=0)

Modified: pkg/raster/man/project.Rd
===================================================================
--- pkg/raster/man/project.Rd	2009-02-04 09:32:22 UTC (rev 245)
+++ pkg/raster/man/project.Rd	2009-02-05 01:33:34 UTC (rev 246)
@@ -1,7 +1,6 @@
 \name{project}
 \alias{projectRaster}
 \alias{projectBbox}
-\alias{makeProj}
 
 \title{Change the projection of a RasterLayer}
 \description{
@@ -23,20 +22,22 @@
 
 \details{
  First create projected bbox (in BasicRaster object). Then project. 
+  
+ See \code{projInfo('proj')}, \code{projInfo('ellps')}, and \code{projInfo('datum')} for options for valid PROJ.4 strings. 
  
- 
- See projInfo('proj'), projInfo('ellps'), and projInfo('datum') for options for valid PROj.4 strings. 
- 
  You can consult this webpage: \url{http://www.remotesensing.org/geotiff/proj_list/} to find the parameter options and names for projections.
  
- Projection is performed using the PROJ.4 library accesed through the rgdal package.  Also see ?CRS
+ Projection is performed using the PROJ.4 library accesed through the rgdal package. Also see \code{?CRS}
 }
 
 \value{
-  a new RasterLayer object (in the R environment), with, in some cases, the side-effect of the raster values written to disk 
+  a new RasterLayer object (in the R environment), with, in some cases, the side-effect of a raster file written to disk 
 }
+
 \author{Robert J. Hijmans}
 
+\seealso{ \code{\link[rgdal]{CRS}}, \code{\link[rgdal]{projInfo}}}
+
 \examples{
 # create a new (not projected) RasterLayer with cellnumbers as values
 r <- raster(-110, -90, 40, 60, ncols=40, nrows=30)



More information about the Raster-commits mailing list