[R-sig-Geo] Function for subsampling spatial data
Adrian Baddeley
Adrian.Baddeley at csiro.au
Thu Aug 26 06:25:24 CEST 2010
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:
> Dear Dr Baddeley and Dr Turner,
>
> I am a Ph.D. student at Imperial College London. I am looking for a
> function that subsamples spatial data such that points are beyond a
> specific distance apart (i.e. all points 1km away from each other; all
> points 3km away from each other etc.). Do you know if such a function
> already exists and if so where I might find it? I wondered if the
> split.ppp function could do this?
>
> Thank you and Kind Regards,
>
> Anna
>
More information about the R-sig-Geo
mailing list