Skip to content

Warning message: points were rejected as lying outside the specified window

5 messages · Adrian Baddeley, Hossain, Md, Rolf Turner

#
Hi,
Apology, my problem may be so simple to answer. I am trying to read disease locations (in longitude and latitude) for 49 adjacent states of USA as an PPP object with the R code:

usdat <- data.frame(x=data$X, y=data2$Y) 
usmap <- map('usa', fill=TRUE, col="transparent", plot=FALSE) 
uspoly <- map2SpatialPolygons(usmap, IDs=usmap$names, proj4string=CRS("+proj=longlat +datum=WGS84")) 
spatstat.options(checkpolygons=FALSE)
usowin <- as.owin.SpatialPolygons(uspoly)
spatstat.options(checkpolygons=TRUE) 
pts <- as.ppp(usdat, W=usowin)
plot(pts)

But, getting the warning messages:
1: point-in-polygon test had difficulty with 2 points (total score not 0 or 1) 
2: In ppp(X[, 1], X[, 2], window = win, marks = marx, check = check) :
  42 points were rejected as lying outside the specified window

Please suggest if there is any way I can keep these 42 points. With regards,

Monir
1 day later
#
On 16/05/14 02:05, Hossain, Md wrote:
Actually you *do* "keep" them.  They form an attribute of your pattern; 
this attribute is called "rejects".  But they get plotted --- with a 
different symbol from the non-rejected points --- when you plot the pattern.

These points are rejected because they lie outside the window that you 
have specified.  If you want them not to be deemed "rejects" you have 
change your window.  Or possibly *move* these points slightly.  Both of 
these strategies are really "cheating" and therefore dubious.

Polygons provided as map boundaries by GIS facilities are almost always 
problematic.  The boundaries are generally very messy --- that's the 
nature of reality.  There is apparently a particular problem with your 
"usowin" window as indicated by the first warning message.  You should 
identify the two points that are causing the difficulty and figure out 
why the problem is arising.

Plot your pattern that has the rejects and examine the rejects.  Figure 
out if there is something weird about them, or about the map boundary 
near where they lie.  Figure out how to fix the weirdness.

To "focus in" on a small region of your window it might be helpful to
use clickpoly():

plot(usowin)
W <- clickpoly(add=TRUE)
# Click on, e.g. 4, points in anticlockwise order to obtain
# a polygon containing the region which you want to examine closely.
# Read the help on clickpoly().
U <- intersect.owin(usowin,W)
plot(U)

You will then probably want to plot the points of "pts" that fall in U
and the points of the rejects that fall in U.  Or perhaps in W:

plot(W)
plot(pts,add=TRUE)
plot(usowin,add=TRUE,border="red")

Things like that should give some insight into what is going wrong and 
perhaps how to fix it.  It will be fiddly.  Good luck.

cheers,

Rolf Turner
#
In addition to Rolf's comments: 
I suggest you make sure you are using the current version
of spatstat (1.37-0).

In the code below you have set 'checkpolygons=FALSE'
before converting from 'SpatialPolygons' to 'owin'.

That was useful in older versions of 'spatstat'
because the checking was time-consuming. However 
turning off the checking carried the risk that the resulting 'owin' object 
could be invalid, causing strange things to happen when we test whether a 
point lies inside the window, etc.

In spatstat version 1.36-0 and later, polygon data is 
automatically repaired by owin() using the package 'polyclip'.
The resulting polygon is always valid; so checking is no longer performed.

So it would be wide to make sure you are running spatstat 1.37-0,
and remove the calls to spatstat.options('checkpolygons').

To inspect the data interactively, you can also use iplot()

regards
Adrian

Prof Adrian Baddeley FAA
University of Western Australia
1 day later
#
Very grateful to Rolf and Adrian for your kind suggestions. Obviously I am going to follow, but it seems there is no quick fix.
In the mean time, just wondering, is there anything that I can do with the "map2SpatialPolygons" function. The data came with the long-lat, but no information about how these long-lats are created, i.e., whether using "WGS84" is apropriate or should I try for other options, e.g., for GCS_North_American_1983_HARN. My knowledge in geography is very poor, please help.

Monir
#
On 18/05/14 14:35, Hossain, Md wrote:
My knowledge about projections and the "datum" concept that is involved 
is nil.  So I can't help you.  Perhaps the maintainers of "sp" and/or 
"maptools" will chime in.  Good luck.

cheers,

Rolf Turner