[R-sig-Geo] Creating density heatmaps for geographical data

Rolf Turner r.turner at auckland.ac.nz
Tue Oct 19 21:24:56 CEST 2010


The spatstat package is designed for the analysis of spatial point
patterns.  In this context the existence of a window --- the
*observation* window --- is absolutely crucial.  You have to know where
points have been *looked for*, because there is information in where
the points aren't, as well as in where they are.  And you can't say
anything about where they aren't unless you know where they have been
looked for.

If you are putting spatstat to other uses where the nature of the process
generating the points is not of interest, and you want a default window
which has the nature of a bounding box, then this is easy to arrange.
E.g. you could write your own simple little utility, say

ppp_koh <- function(x,y,wrecked=TRUE,f,marks=NULL) {
require(spatstat)
ppp(x,y,window=ripras(x,y,shape=if(wrecked) "rectangle" else "convex",f=f),marks=marks)
}

Then you can do things like:
set.seed(42)
x <- runif(100,3,7)
y <- runif(100,-2,9)
X <- ppp_koh(x,y)

Note that by default the ripras() function called by ppp_koh() expands the
bounding box of the points slightly from extent of the data (to give a ``maximum
likelihood estimate'' of the bounding box).

If you don't want this expansion then specify f=1:

Y <- ppp_koh(x,y,f=1)

Note that this will cause at least two points of the pattern (and probably
four or more) to lie on the boundary of the window.

In genuine spatial point process applications one is advised to eschew
the use of the ripras() function.

	cheers,

		Rolf

On 19/10/2010, at 11:58 PM, Karl Ove Hufthammer wrote:

> Rolf Turner wrote:
> 
>>> 'ppp' objects used by 'spatstat' have an annoying structure
>> 
>> <SNIP>
>> 
>> Annoyance is in the mind of the beholder I think.  Personally I
>> find the structure of ppp objects absolutely *delightful*! :-)
>> 
>> Also, they are simple, intuitive, easy to work with, and easy to
>> understand, take apart, dissect, and manipulate.  Furthermore the
>> tools in spatstat make it easy to do unto ppp objects pretty well
>> anything one might want to do to a point pattern.  (I'm not being
>> immodest here; the tools are mainly down to Adrian.)
>> 
>> Just what do you find ``annoying'' about the structure of ppp objects?
> 
> Well, I guess only the fact that they’re not ‘sp’ objects, really. And
> that’s very annoying … :)
> 
> And though the ‘window’ element of ‘ppp’ objects may be of use to some 
> people, I haven’t had any use for it. The annoying thing here is that the 
> constructor doesn’t generate the window automatically, based on the extent / 
> bounding box of the data, and don’t have an *option* for doing this, either.
> Whenever I have used ‘spatstat’ (not too often), I have had to spend too 
> much time looking up how the window should be specified. Having [0,1] × 
> [0,1] as the *default* window, and excluding any points outside this does 
> seems like a strange design decision.



More information about the R-sig-Geo mailing list