[R-sig-Geo] new patch versus patch expansion
Robert J. Hijmans
r.hijmans at gmail.com
Thu Jun 12 07:58:21 CEST 2014
Jonathan,
I am not sure if this improves things, but it is an alternative route:
a <- boundaries(t1, type='outer', classes=TRUE, directions=4)
f1 <- freq(c.change, useNA='no')
f2 <- freq(mask(c.change, a, maskvalue=0), useNA='no')
f <- merge(f1, f2, by='value')
newpatches <- f[f[,2] == f[,3]]
Robert
On Tue, Jun 10, 2014 at 4:49 AM, Thompson, Jonathan
<jthomps at fas.harvard.edu> wrote:
> 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 at fas.harvard.edu <mailto:jthomps at fas.harvard.edu%20>
>
>
> [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
More information about the R-sig-Geo
mailing list