I am hoping for some help thinking through a problem.  I need to quantify the percent of new urban patches (not cells) in a land cover change map that occur as expansion of existing urban patches versus those that occur as new patches. And I need to do this over a very large area (>40mil cells).     I developed a toy solution below but it is terribly inefficient and when applied to the full dataset the vector produced from the adjacent command is prohibitively large.   My fear is that I’m overlooking an obvious solution.   I would sure appreciate any ideas.  Thanks in advance.

library(raster); library(SDMTools)
set.seed(10)
### Time One Raster  ############
t1 <- raster(ncol=5, nrow=5)
vals <- sample(c(0,1,0,0,0), ncell(t1), replace =T)
t1[] <- vals

### Change Raster #########
change<- raster(ncol=5,nrow=5)
change[] <- rep(0, times = ncell(change))
vals.c <- sample(which(vals==0), 5)
change[vals.c]=1

### Time Two Raster #########
t2 <- t1 + change

### Define and count Patches #####
c.change <- clump(change)
change.patches <- PatchStat(c.change, cellsize = 1)

## define those cells that are adjacent to Time One Urban Cells
adj.cells <- adjacent(t1, which(values(t1)==1), pairs = F)

## Which of those are occupied by a new patch
adj.patches <- extract(c.change,adj.cells)

## What percent of patches are adjacent to existing patches
(length(unique(adj.patches))-1) / length(unique(change.patches$patchID))



Jonathan R Thompson, Ph.D.
Harvard Forest   |  Harvard Univeristy
324 North Main Street, Petersham Massachusetts 01366
Phone 978-756-6145  | Email jthomps@fas.harvard.edu <mailto:jthomps@fas.harvard.edu%20>


	[[alternative HTML version deleted]]

