[R-sig-Geo] Warning message: points were rejected as lying outside the specified window
Rolf Turner
r.turner at auckland.ac.nz
Sat May 17 02:29:08 CEST 2014
On 16/05/14 02:05, Hossain, Md wrote:
> 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.
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
More information about the R-sig-Geo
mailing list