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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jan 28 17:00:58 CET 2009


Author: rhijmans
Date: 2009-01-28 17:00:58 +0100 (Wed, 28 Jan 2009)
New Revision: 203

Removed:
   pkg/raster/R/polygon.to.raster.R
Modified:
   pkg/raster/R/polygonToRaster.R
Log:
polygonsToRaster

Deleted: pkg/raster/R/polygon.to.raster.R
===================================================================
--- pkg/raster/R/polygon.to.raster.R	2009-01-28 15:53:54 UTC (rev 202)
+++ pkg/raster/R/polygon.to.raster.R	2009-01-28 16:00:58 UTC (rev 203)
@@ -1,58 +0,0 @@
-# Author: Robert J. Hijmans, r.hijmans at gmail.com
-# International Rice Research Institute
-# Date :  June 2008
-# Version 0,1
-# Licence GPL v3
-
-
-#UNDER DEVELOPMENT
-.polygon.to.raster <- function(sppoly, raster) {
-# check if bbox of raster and sppoly overlap
-	spbb <- bbox(sppoly)
-	rsbb <- bbox(raster)
-	if (spbb[1,1] > rsbb[1,2] | spbb[2,1] > rsbb[2,2]) {
-		stop('polygon and raster have no overlapping areas')
-	}
-	npol <- length(sppoly at polygons)
-	info <- matrix(NA, nrow=npol, ncol=3)
-	for (i in 1:npol) {
-		info[i,1] <- length(sppoly at polygons[[i]]@Polygons)
-		miny <- NULL
-		maxy <- NULL
-		for (j in 1:info[i,1]) {
-			miny <- min(miny, min(sppoly at polygons[[i]]@Polygons[[j]]@coords[,2]))
-			maxy <- max(maxy, max(sppoly at polygons[[i]]@Polygons[[j]]@coords[,2]))
-		}
-		info[i,2] <- miny
-		info[i,3] <- maxy
-	}
-	lxmin <- min(spbb[1,1], rsbb[1,1]) - xres(raster)
-	lxmax <- max(spbb[1,2], rsbb[1,2]) + xres(raster)
-	for (r in 1:nrow(raster)) {
-		ly <- yFromRow(raster, r)
-		uly <- ly + 0.01 * yres(raster)
-		lly <- ly - 0.01 * yres(raster)
-		for (i in 1:npol) {
-			if (info[i,2] > uly | info[i,3] < lly) {
-				# do nothing
-			} else {
-				for (j in 1:info[i,1]) {
-					if ( max ( sppoly at polygons[[i]]@Polygons[[j]]@coords[,2] ) < ly  |  min( sppoly at polygons[[i]]@Polygons[[j]]@coords[,2] ) > ly ) {
-						# do nothing
-					} else {
-						cds <- sppoly at polygons[[i]]@Polygons[[j]]@coords
-						c1 <- rbind(cds[length(cds[,1])], cds)
-						c2 <- rbind(cds, cds[1])
-						cds <- cbind(c1, c2)
-						intlines <- cds[cds[ (cds[,2] < ly & cds[,4] > ly ) | (cds[,2] > ly & cds[,4] < ly)] ,]
-						print(intlines)
-					}	
-				}
-			}
-		}	
-	}
-	return(info)
-}
-
-#polygon.to.raster(nld, rs)
-

Modified: pkg/raster/R/polygonToRaster.R
===================================================================
--- pkg/raster/R/polygonToRaster.R	2009-01-28 15:53:54 UTC (rev 202)
+++ pkg/raster/R/polygonToRaster.R	2009-01-28 16:00:58 UTC (rev 203)
@@ -149,7 +149,8 @@
 
 
 polygonsToRaster2 <- function(sppoly, raster, field=0, filename="", overwrite=FALSE) {
-# should be slower except when  polygons very detailed and raster las ow resolution
+#  This is based on sampling by points. Should be slower except when  polygons very detailed and raster las ow resolution
+# but it could be optimized using the bounding boxes ofindividual polygons.
 
 # check if bbox of raster and sppoly overlap
 	filename <- trim(filename)



More information about the Raster-commits mailing list