[Raster-commits] r454 - pkg/raster/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue May 12 11:17:00 CEST 2009
Author: rhijmans
Date: 2009-05-12 11:16:41 +0200 (Tue, 12 May 2009)
New Revision: 454
Modified:
pkg/raster/R/clump.R
Log:
Modified: pkg/raster/R/clump.R
===================================================================
--- pkg/raster/R/clump.R 2009-05-12 08:36:41 UTC (rev 453)
+++ pkg/raster/R/clump.R 2009-05-12 09:16:41 UTC (rev 454)
@@ -72,8 +72,19 @@
if (tmpfile1 == "") {
x1 <- setValues(x1, v)
}
- rcl <- unique(rbind(rcl, cbind(rcl[,2], rcl[,1])))
- rcl <- rcl[rcl[,1] < rcl[,2],]
+ rcl1 <- unique(rbind(rcl, cbind(rcl[,2], rcl[,1])))
+ rcl <- rcl1[rcl1[,1] > rcl1[,2],]
+ aggrcl1 <- aggregate(rcl, by=list(rcl[,1]), FUN=min)[,-1]
+ colnames(rcl) <- c('a', 'b')
+ colnames(aggrcl1) <- c('a', 'c')
+ aggrcl2 <- merge(rcl, aggrcl1)[,-1]
+ aggrcl2 <- aggrcl2[aggrcl2[,1] != aggrcl2[,2],]
+ colnames(aggrcl2)[1] <- 'a'
+ aggrcl <- rbind(aggrcl1, aggrcl2)
+ aggrcl <- aggregate(aggrcl, by=list(aggrcl[,1]), FUN=min)[,-1]
+ rcldown <- aggrcl[rev(order(aggrcl[,1])), ]
+
+ rcl <- rcl1[rcl1[,1] < rcl1[,2],]
aggrcl1 <- aggregate(rcl, by=list(rcl[,1]), FUN=max)[,-1]
colnames(rcl) <- c('a', 'b')
colnames(aggrcl1) <- c('a', 'c')
@@ -82,9 +93,11 @@
colnames(aggrcl2)[1] <- 'a'
aggrcl <- rbind(aggrcl1, aggrcl2)
aggrcl <- aggregate(aggrcl, by=list(aggrcl[,1]), FUN=max)[,-1]
- aggrcl <- aggrcl[order(aggrcl[,1]), ]
+ rclup <- aggrcl[order(aggrcl[,1]), ]
- rclm <- cbind(aggrcl[,1], aggrcl)
+ rclcomb <- rbind(rcldown, rclup)
+
+ rclm <- cbind(rclcomb[,1], rclcomb)
if (tmpfile1 == "") {
x1 <- reclass(x1, rclm, update=TRUE, filename=filename, datatype=datatype, overwrite=overwrite)
return(x1)
More information about the Raster-commits
mailing list