[R-sig-Geo] Euclidean Nearest Neighbour

Gilles Benjamin Leduc gbl1 at hi.is
Mon Oct 5 17:39:55 CEST 2015


I try to  understand... 

So, 

First install this dev package: Linarius. 

library(devtools) 
install_github("giby/Linarius) 
library(Linarius)
 
Then lets load a test dataset: 

data(Leymus)

You may find the distances between all your spot like this 

distGPS(locations[,1], locations[,2],rownames(locations)) #by default use the Lambert approximation 


So lets create a matrix to work on: 

as.matrix(distGPS(locations[,1], locations[,2],rownames(locations)))->distances 

Ugly way to remove 0: 

distances[distances==0]<-100000


then obtain the minimal distance from every place: 
apply(distances,1,min) #look what you obtain 
apply(distances,1,min)->min.dist #keep this object 

 Lets now introduce the type of every place 

type<-c("Artificial", "Pine forest", "Mixed forest", "Oak forest", "Shrublands","Artificial", "Pine forest", "Mixed forest", "Oak forest", "Shrublands","Artificial", "Pine forest", "Mixed forest", "Oak forest") #I just made up this randomly 

Here obtain the mean of minimal distance of Oak forest with any other: 
mean(min.dist[type=="Oak forest"]) 

here obtain the mean minimal distance of every Oak forest to another: 


mean(apply(distances[type=="Oak forest",type=="Oak forest"],1,min)) 

Is one of these that what you tried to do ?

Benjamin 

 
Le Lundi 5 Octobre 2015 14:17 GMT, juan jose mena <juamecos at gmail.com> a écrit: 
 
> Hi Benjamin,
> 
> I have a Land Cover map with 5 different classes (i.e. Artificial, Pine
> forest, Mixed forest, Oak forest and Shrublands). what I want to compute is
> the mean euclidean nearest neigbour distance between all the patches in all
> the classes as Fragstats does:
> '' ENN = hij, distance (m) from patch ij to nearest neighboring patch of
> the same type (class), based on patch edge-to-edge distance, computed from
> cell center to cell center (FRAGSTATS HELP p. 138)''.
> Thanks in advance,
> 
> Juan
> 
> 2015-10-05 15:52 GMT+02:00 Gilles Benjamin Leduc <gbl1 at hi.is>:
> 
> > Hi,
> >
> > Are you talking about euclidian distances between location (physical
> > distance)  or  between two genotype (genetic distance) or between two
> > populations (also genetic distance, but not the same).
> >
> > I might have an answer for three of them :p
> >
> > Benjamin
> >
> >
> > Le Lundi 5 Octobre 2015 11:28 GMT, juan jose mena <juamecos at gmail.com> a
> > écrit:
> >
> > > Hi all,
> > >
> > > I am performing a Landscape structure analysis with a raster layer and
> > > using SDMtools package in R. I got some metrics of my interest by means
> > of
> > > ClassStat and PatchStat functions but any of them perform the Euclidean
> > > Nearest Neighbour. So, any of you could tell me a package or a function
> > to
> > > calculate this metric or another connectivity metric to analyze the
> > > isolation?
> > >
> > > Thanks in advance
> > >
> > > Juan José Mena Costa
> > >
> > >       [[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