I am using the Jfox function in spatstat to explore the distance of points in a point pattern to the nearest polygon between a set of points and a set of polygons in an area.

my code is something like:

Jfox(X=points, Y=win)

where points is the point pattern object, while win is the owin that represent the polygons from which I want to calculate the distance from my points.

When I run the code I, so far, always get a warning saying

In resolve.foxall.window(X, Y, W) :
  Trimming the window of X to be a subset of the Frame of Y

I tried to understand what it means by looking into the code of the resolve.foxall.window function (available here https://rdrr.io/cran/spatstat/src/R/GJfox.R) and plotting the frame of Y, along with the points and the points' window.

I obtained this plot: enter image description here


  • the open circle is my point (I know it's only one and probably not worth the analysis but this was actually the case that got my attention because, when trimming the window, the point was excluded from the computation and thus the absence of points in the trimmed window generated an error)
  • the solid red polygons are my polygons stored in the win object.
  • the black outline is the Window of the point pattern (the irregular shape is because it was an photographic collage)
  • the green square is the Frame of points
  • the red square (partially overlapped by the blue shape) is the Frame of win

and finally

  • the blue shape is the trimmed window resulting from the instersection of the Frame(Y) with Window(X) in the resolve.foxall.window function.


  1. From this it seems that only the points falling within the trimmed Window (i.e. the blue shape) will ever be considered for the estimate of the Jfox function (and similarly the Gfox). Is this correct?
  2. If this 1 is correct, does this depend on the fact that for points outside the trimmed windows it is not possible to measure a distance with some feature (another polygon) that may potentially be present outside the Window of observation of the points (i.e. the black outline, my area of study)?
  3. Always if 1 is correct, does it means that is then impossible to calculate a Jfox or Gfox distance in the case there is only 1 polygon in the object win?
  4. Could it be correct to make the Frame(Y) as big as the Window(X) to include all the points in a ppp?

Thanks for a well described problem. The code for Jfox (together with most of spatstat) was written by Adrian Baddeley, and I just passed your question to him. The reply was:

In order to estimate Jfox, the objects X and Y must each have a "window" inside which they are observed. The principle is that we must determine which parts of the 'observation window' did or did not contain the features X and Y.

If Y is a point pattern (class ppp) or line segment pattern (class psp), then the object's data structure includes the 'window' in which the points or lines were observed. So in this case, the calculations are performed using the 'observation window' defined as intersect.owin(Window(X), Window(Y)).

For convenience, the code for Jfox also allows Y to be a window (class owin) representing a spatial feature. The problem arises because spatstat does not have a data type for 'window observed within a window'. So by default, the observation window is taken to be Frame(Y), which is probably not what you intended.

Can you specify the study region for your polygons, i.e. the region of space W which was surveyed in order to determine the presence and location of your polygons? If so, then I recommend you convert your window Y to a logical-valued image as follows:
Z <- as.im(FALSE, W)
Z[Y] <- TRUE
Then use Z instead of Y, i.e. calculate Jfox(X, Z).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.