[R-sig-Geo] neighbour patches

Jacob van Etten jacobvanetten at yahoo.com
Sun Feb 27 23:37:20 CET 2011


Hi Patrick,

Nice question. This would be my approach:

#------------------------

library(raster)

#make "patches"
r <- raster(ncols=10, nrows=10)
r[] <- round(runif(ncell(r))*0.7)
rc <- clump(r)

#take a look
plot(rc)

#some preparation
n <- max(getValues(rc),na.rm=TRUE)
m <- matrix(NA,n,n)

#now calculate distances
for(i in 1:n)
{
  gd <- gridDistance(rc, origin=i)
  m[,i] <- zonal(gd, rc, min)[,2]
}

#and voilà
m <- as.dist(m)
m

#------------------------

Alternatively, you could use the function distance() instead of gridDistance(). The advantage of gridDistance() is that you can indicate if animals can or cannot move through certain areas (optional argument 'omit', now not used). The disadvantage is that it is less precise than distance() -- it creates 'hexagonal' distance patterns.

Jacob.

--- On Sat, 26/2/11, Patrick Giraudoux <patrick.giraudoux at univ-fcomte.fr> wrote:

> From: Patrick Giraudoux <patrick.giraudoux at univ-fcomte.fr>
> Subject: [R-sig-Geo] neighbour patches
> To: r-sig-geo at r-project.org
> Date: Saturday, 26 February, 2011, 8:54
> Hi,
> 
> I am tempted to dig in graph theory and analyse connections
> between discrete landscape patches. Re-reading 'Applied
> Spatial Data Analysis with R' I was happy to find basics
> chapter 9. However, it reports on graphs where (euclidian)
> distance is computed between patch centroids.
> 
> Does anybody have an idea about strategies or packages
> permitting to use the shortest distance between patch
> borders instead (which is more realistic with regard to
> animal movement) ?
> 
> Patrick
> 
> _______________________________________________
> 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