[R-sig-Geo] Distance rule that filtering a set of points in "ppp" class by minimum or maximum distance

Rolf Turner r@turner @end|ng |rom @uck|@nd@@c@nz
Fri Aug 28 13:37:41 CEST 2020


On Thu, 27 Aug 2020 21:17:58 -0400
ASANTOS via R-sig-Geo <r-sig-geo using r-project.org> wrote:

> Dear R-Sig_Geo Members,
> 
> I'd like to find a more simple way to filtering a set of points in a 
> "ppp" object by minimum or maximum distance.
> 
> In my example using a ants ("ppp" object) in spatstat package:
> 
> #Packages
> library(spatstat)
> library(sp)
> 
> #Point process example
> data(ants)
> str(ants)
> #- attr(*, "class")= chr "ppp"
> 
> #Computes the matrix of distances between all pairs of ants nests and 
> selection of more than 20 m distance neighborhood
> ants.df<-as.data.frame(ants)
> coordinates(ants.df) <- ~x+y
> ants.dmat <- spDists(ants.df) #Calculate a distance matrix using
> spDists min.dist <- 20 #distance range
> ants.dmat[ants.dmat <= min.dist] <- NA # Na for less than 20 meters
> 
> Here yet I need to start a relative long code for identified columns 
> with NA in ants.dmat object, create a new data frame and than create
> a new ppp object based in the coordinates and marks etc...
> 
> Is there any more easy way for create a new "ppp" object just only 
> specified a distance rule that filtering a set of points in a
> original "ppp" object by minimum or maximum distance?
> 
> Thanks in advanced,
> 
> Alexandre
> 

It's very easy! :-)

ddd <- nndist(ants)
farAnts <- ants[ddd >= 20]

cheers,

Rolf

-- 
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276



More information about the R-sig-Geo mailing list