Skip to content
Prev 9106 / 29559 Next

Function for subsampling spatial data

Dear Anna

If I understand correctly, you want to select a subset of points in a 
point pattern so that the selected points are all separated from one 
another by a specified distance.

There could be more than one way to select such a subset. So this is not 
a well-defined task.

However here is one way to do it. In addition to the 'spatstat' package 
we need the package 'gcolor'. In the example I use the dataset 'redwood' 
for demonstration, and I chose the threshold distance to be 0.11 units.

       library(spatstat)
       library(gcolor)
       data(redwood)
       close <- (pairdist(redwood) <= 0.11)
       tag <- ineq(close)
       tag <- factor(tag)
       X <- redwood %mark% tag
       Y <- split(X)
       plot(Y)

On the fourth line, we use spatstat to calculate the distance between 
all pairs of points in the point pattern 'redwood', and then create a 
logical matrix 'close' whose entries are TRUE if the corresponding pair 
of points is closer than the threshold distance of 0.11 units.

Now imagine that we draw a straight line between each pair of points in 
the redwood pattern that lie closer than 0.11 units apart. Then we have 
a graph or network, and we want to select a subset of points so that any 
two points in the subset are not joined directly by a line. Well this 
would be equivalent to attaching a colour to each point in the redwood 
pattern, such that any two points that are joined by a line must have 
different colours. This can be accomplished by a 'graph colouring 
algorithm'. The package 'gcolor' provides this.

On the fifth line we use 'gcolor' to produce a colouring of the graph 
represented by the matrix 'close'.  The function 'ineq' computes a graph 
colouring. The result is a vector of integers representing the colours 
of each point. There are 7 colours.

In the subsequent lines we convert the integers to a factor, attach this 
to the redwood pattern as a mark, and then (as you guessed) use 
split.ppp to separate the differently coloured points.

In the split pattern Y, each component Y[[1]], Y[[2]] etc is a subset of 
the kind you were wanting. There are 7 components.

I hope this is what you were seeking

best wishes
Adrian Baddeley
On 24/08/10 20:52, Songhurst, Anna wrote: